I am wondering what loop I need to use for when the condition is not met.
I want to make it so that when the user enters a letter other than 'h' or 'l', the user will be redirected to the question.
int main()
{
srand((unsigned)time(NULL));
cout<<"Welcome" <<endl;
int comp1=rand()%101+1;
int comp2=rand()%101+1;
char choice;
cout<<"The computer has generated the number:"<<comp1<<endl;
cout<<"Do you think the next number will be higher or lower? Please enter 'h' or 'l'.";
cin>>choice;
if(choice=='h'||choice=='H')
{
cout<<"The computer has generated the number:"<<comp2<<endl;
if(comp2 > comp1)
{
cout<<"Congratulations! You win!"<<endl;
}
else
{
cout<<"I'm sorry. You lose!"<<endl;
}
}
elseif(choice=='l'||choice=='L')
{
cout<<"The computer has generated the number:"<<comp2<<endl;
if(comp2 < comp1)
{
cout<<"Congratulations! You win!"<<endl;
}
else
{
cout<<"I'm sorry. You lose!"<<endl;
}
}
else
{
cout<<"Invalid input."<<endl;
}