Thanks for the simplification!
By putting just (x) after the while statement, am I right in thinking that the loop continues as long as x has a positive value then?
I am now 98% close to being there - played with different variations of my code until the wee hours - but am definitely still missing a little something.
Input of letters are excluded from the beginning with correct loop function - great, then wrong number input functions also - great.
The 'wrong' numbers are excluded from the beginning with correct functioning of the loop - good. However if a 'letter' is subsequently entered, I run into the whole input staying in the buffer problem.
Problem also occurs if I enter letters, followed by an unacceptable number, followed by another letter.
I tried putting one while loop into the other amongst other things but to no avail.
here is the code at present - including your simplification!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
#include <iostream>
#include <string>
#include <limits>
using namespace std;
int main ()
{
int x=0;
bool right_integer = false;
cout << "your number please:-" << endl;
while (!(cin >> x))
{
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(),'\n');
cout << "Please input a proper 'whole' number between 0 and 100000, thank you!: " << endl;
}
while (!right_integer)
{
if (x <= 100000 && x > 0)
{
right_integer = true;
}
else
{
cout << "Pick a 'whole' positive number please between zero and 100000:" << endl;
cin >> x;
}
}
while (x)
{
cout << x-- << " ";
}
cout << endl << "All done! Nice!!" << endl;
return 0;
}
|