0

C++

I want to ask if you can let user input a specific number you want in c++ Example :user will be to input numbers from 1 to 30 only

12th Jun 2024, 11:34 PM
Alhassan Emmanuel
Alhassan Emmanuel - avatar
3 Answers
+ 4
Alhassan Emmanuel #include <iostream> using namespace std; int main() { int days; cin >> days; if ((days < 1 ) || ( days > 30 )) { cout << "out of range"; } else { cout << "whatever you want";} return 0; }
13th Jun 2024, 3:50 AM
BroFar
BroFar - avatar
+ 2
intro to C++ is waiting for you
13th Jun 2024, 2:07 PM
Alhaaz
Alhaaz - avatar
0
I think what you have to do is put the input statement in a loop that runs as long as the value is not valid.
12th Jun 2024, 11:40 PM
Wilbur Jaywright
Wilbur Jaywright - avatar