Hi guys so for fun I'm trying to translate this video to code: https://www.youtube.com/watch?v=7hhQLozezak
I want it to go
+"You stupid"
+"No I'm not" (or any small grammatical variants). If they say anything off script they get "Later dude..."
+"What's 9+10?"
If they respond with 21, the code ends. If they say anything else, the code loops back to the start.
When it loops back however, it doesn't ask again for the answer to 9+10, it just skips over to "Later dude..."
I watched this guy's video to understand how to input strings https://www.youtube.com/watch?v=AgS9JSzbvtU&list=PLZUHVRLMZd8S-F4PupuAgdf0j9C3cA9Sd&index=2
But I think it's causing the problem with this loop. Are there any alternative ways of getting a string input that'll loop properly?
#include <iostream>
using namespace std;
int main()
{
int answer;
string noImNot;
string noImNotCorrect1 = "No I'm not";
string noImNotCorrect2 = "No i'm not";
string noImNotCorrect3 = "no I'm not";
string noImNotCorrect4 = "no i'm not";
string noImNotCorrect5 = "No Im not";
string noImNotCorrect6 = "No im not";
string noImNotCorrect7 = "no Im not";
string noImNotCorrect8 = "no im not";
while (answer != 21)
{
cout << "You stupid\n";
getline(cin, noImNot);
cin.ignore();
bool noImNotBool = (noImNot == noImNotCorrect1 || noImNot == noImNotCorrect2 || noImNot == noImNotCorrect3 || noImNot == noImNotCorrect4 || noImNot == noImNotCorrect5 || noImNot == noImNotCorrect6 || noImNot == noImNotCorrect7 || noImNot == noImNotCorrect8);
//The bool only seemed to work when I put it AFTER the getline, not before...
if (noImNotBool == false)
{
cout << "Later dude...";
exit(0);
} else {
cout << "What's 9+10?\n";
cin >> answer;
}
}
cout << "Correct.";
return 0;
}