Loop until

How do I loop this until the negative number is entered and only the negative number

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
bool run_menu = true;
	while (run_menu) {
cout << "Please Enter your number ";
		cin >> idnumber;
		if (idnumber == -1) {
			cout << "Please Enter your number " << endl;
			run_menu = false;
		}






1
2
3
4
5
int n;
while((std::cout << "Please enter a non-negative number: ") && (std::cin >> n) && (n < 0))
{
    std::cout << n << " is negative, try again." << std::endl;
}
Last edited on
Topic archived. No new replies allowed.