cs161ASpring2024/yorn.cpp

37 lines
962 B
C++

#include <iostream>
using namespace std;
// write a program to demonstrate how to use while-loops to make
// yes or no prompts
int main(){
string answer;
int tries = 3;
//cout << "enter either y for yes or n for no (y/n): " << endl;
//cin >> answer;
//while(answer != "y" && answer != "n"){
// cout << "enter either y for yes or n for no (y/n): " << endl;
// cin >> answer;
//}
// ! (a || b) <-> !a && !b
// ! (a && b) <-> !a || !b
//while(! (answer == "y" || answer == "n")){
// cout << "enter either y for yes or n for no (y/n): " << endl;
// cin >> answer;
//}
do {
cout << "enter either y for yes or n for no (y/n): " << endl;
cin >> answer;
tries = tries - 1;
} while(! (answer == "y" || answer == "n") && tries > 0);
if(! (answer == "y" || answer == "n")){
cout << "wow, I guess you didn't want to answer that" << endl;
}
else{
cout << "you said: " << answer << endl;
}
return 0;
}