keeping a variable in between two numbers

I have a variable named int tripHours. The number of hours is suppose to be at least one and less than 10,000 and if it is not there should be a statement that gives an error message. How would i write that into my program?
So far I have...

int tripHours;

cout<< "Enter the number of hours for the delivery trip.";
cin>> tripHours;

...after that what should i put so that triphours is at least one and less then 10,000?

cout<<"WARNING:" << tripHours <<"is and invalid input. Try again" << endl;
Last edited on
1
2
3
if(tripHours<1 || tripHours>10000){
                         cout<<"WARNING:" << tripHours <<"is and invalid input. Try again" << endl;
}
thanks a lot
I got it so that the correct error message appears when a wrong number is entered, but if the user enters a wrong number i dont want the program to end. I need it to run "Enter the number of hours for the delivery trip." again every time a wrong answer is giving. Any help on how to do that would be appreciated.

thanks in advance
Use a loop.
i was trying too but it gave me the error message over and over. I am new too all of this, could you please show me how to do this correctly.

thanks
You should probably look in the tutorial section of this site first; it has information about how loops work.
Topic archived. No new replies allowed.