- #316
jtbell
Staff Emeritus
Science Advisor
Homework Helper
- 15,987
- 6,483
You can't do that with the input statement alone. Consider that it would also need to have some way to specify what you want to happen if the number is > 1000.yungman said:How do I limit say number <=1000?
You need to read whatever the user enters, then test it yourself. If it doesn't meet your condition, do whatever you think is appropriate. For example, if you want to display an error message and ask the user to try again:
C:
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
int main ()
{
int inputNum;
cout << "Enter a number <= 1000: ";
cin >> inputNum;
while (inputNum > 1000)
{
cout << "Hey dummy, I said <= 1000! Try again: ";
cin >> inputNum;
}
cout << "OK, you entered " << inputNum << "." << endl;
return 0;
}