Hi everyone, I'm a beginner in c++ and I'm playing around with using break, and I created this small basic program. What I'm trying to do is letting the user input both string words. But for some reason it's saying incorrect, please help.
#include <iostream>
#include <string>
usingnamespace std;
int main() {
// First I did this string favMovie = "Wedding Ringers"
// Then I did this string favMovie = "Wedding", it worked fine when the user input just that one word.
string favMovie = "Wedding "" Ringers";
string input;
do{
cout << "What is my favorite movie?" << endl;
cin >> input;
if (input==favMovie)
{
break;
}
else{
cout << "You are incorrect, try again!" << endl;
}
}while(true);
cout << "You are correct!" << endl;
return 0;
}
Start some debugging to see what your problem might be. In your 'else' clause, try printing the value of input and see what it says, and if it reflects what you expect from your input.
Thank you Softrix, it worked! And booradley60 I did that and everything was in it's right place. I was just missing a getline(cin,input); like Softrix recommend above.