Need help with my program, not working!

closed account (yR9wb7Xj)
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.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
 #include <iostream>
#include <string>
using namespace 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;
}
Last edited on
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.

cin will read until it reaches the whitespace, so entering Wedding Ringers you will only have Wedding in your input variable. Look at using getline:

getline(cin, input);

http://www.cplusplus.com/reference/string/string/getline/
closed account (yR9wb7Xj)
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.

Your Welcome :)
Topic archived. No new replies allowed.