Hello,
Complete beginner here, really enjoying learning to code. Currently trying to fix up a fun program for my dad for Father's Day. I have already written an introduction of sorts with a few multiple choice questions; however, I am having trouble writing a "free response" question of sorts.
Basically, what I want to do is ask a question like "Who is my favorite actor?" Then have him input an answer choice, eliciting a statement depending on whether he answers right or wrong.
Something like this:
"Who is my favorite actor?"
if Tom Hanks cout << "Nice job!"
else cout << "That's too bad..."
Despite hours of messing with it and searching for an answer, my newbness cannot get it right. I see that I can't 'cin' a two word answer with integers, so I tried getline (), but I am not sure how to if-else with that. So if you could help, that'd be awesome!
I know there are many things wrong with this particular segment of code. But this was my base, and every direction I try to go from here fails as well.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
#include<windows.h>
#include <iostream>
#include <string>
using namespace std;
string actorstr;
cout << "\n\n\t 1. Who is my favorite actor?";
getline (cin, actorstr);
if (actorstr == Tom Hanks) cout << "Nice job!";
else cout << "Ooo, wrong again...";
|
Sidenote: I have already been using the cin command with variables and getline () earlier in the program, and I heard mixing the two isn't preferable, and when I try to use getline () again, it doesn't even show on output.
Sorry for the lengthy post! I appreciate any input!