My problem is that the code only works properly when I type in one character at a time so if I type in 'k' I get
cout<<"Remember the program only understands y or n as an answer. It won't even understand yes or no"<<endl;
cout<<"Do you want to give it a new try?"<<endl;
But if I write two characters for example 'ko' I get the same output twice like this
cout<<"Remember the program only understands y or n as an answer. It won't even understand yes or no"<<endl;
cout<<"Do you want to give it a new try?"<<endl;
cout<<"Remember the program only understands y or n as an answer. It won't even understand yes or no"<<endl;
cout<<"Do you want to give it a new try?"<<endl;
#include <iostream>
#include <iomanip>
usingnamespace std;
int main(){
int x;
char answer,answer2;
do{
do{
cout<<"Type in an integer"<<endl;
cin>>x;
if(x<56){
cout<<"YOU LOSE"<<endl;
}
elseif (x>78){
cout<<"YOU LOSE"<<endl;
}
else{
cout<<"YOU WIN"<<endl;
}
cout<<"Wanna try again. Pres y for yes and n for no"<<endl;
cin>>answer;
}
while(answer=='y');
if(answer=='n'){
}
else{
do{
cout<<"Remember the program only understands y or n as an answer. It won't even understand yes or no"<<endl;
cout<<"Do you want to give it a new try?"<<endl;
cin>>answer2;
}
while(answer2 != 'y' && answer2 != 'n');
}
}
while(answer2=='y');
cout<<"Thanks for trying!";
return 0;
}
The same as when I type in one character fx 'k' so the output will be
cout<<"Remember the program only understands y or n as an answer. It won't even understand yes or no"<<endl;
cout<<"Do you want to give it a new try?"<<endl;