I input 6, which is greater than 5, from the given if function.
So the program will output:
"Invalid. Please enter the designated number of the given choices"
What I want to happen is that when I input 6,
the output should be like this:
"Invalid. Please Enter the designated number of the given choices"
and the program will go back to the statement
"Press any key ranging from 1 ~ 5"
and the previous statements will be cleared.
cout << "Press any key ranging from 1 ~ 5"<<endl;
cin >>b;
if (b<1 || b>5)
{
cout << "Invalid. Please enter the designated number of the given choices."<<endl<<endl;
But how will it end? :|
For ex, I need to check whether b<1 || b>5.
If it's False:
if (b==1){
c=c+1;}
else if (b==2){
d=d+1;}
else if (b==3){
e=e+1;}
else if (b==4){
f=f+1;}
else if (b==5){
g=g+1;}
OR you can use the Switch statement:
(You need to know about functions)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
//(declare this as a function, and declare another tiny function that opens //this function back)
switch (userinput)
{
case: 1
// do the 1 processing
break;
...
case: 5
// do the 5 proseccing
default:
cout<<"Invalid number. Please try again";
tinyfunc();
break;
}
I dont know if this method works with characters...