keeping a variable in between two numbers

Sep 30, 2009 at 3:30am
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 Sep 30, 2009 at 3:03pm
Sep 30, 2009 at 3:39am
1
2
3
if(tripHours<1 || tripHours>10000){
                         cout<<"WARNING:" << tripHours <<"is and invalid input. Try again" << endl;
}
Sep 30, 2009 at 3:48am
thanks a lot
Sep 30, 2009 at 2:38pm
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
Sep 30, 2009 at 7:51pm
Use a loop.
Oct 1, 2009 at 1:18am
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
Oct 1, 2009 at 7:57pm
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.