Jumble Game I am working on If/Else Statement Problems

I am working on a basic game. I have it so there can be a level select. It asks for a number (level number) For example: you quit on level two. You restart the program. You type 2 on the select puzzle part and it brings you to level two in this case potato. Instead what it does is bring me straight to WRONG! ABORT PROGRAM! If you need more detail just let me know. Otherwise potential fix would be much appreciated. Thanks, Cheers, Adios!

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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
  #include <iostream>

int main(){
using namespace std;
int x;
int y ;
string YourAnswer;
string Continue;
cout<<"Welcome to Jumble!";
cout<< endl;
cout<<"We have over 3 words to unjumble!";
cout<< endl;
cout<<"Select a number. Each number represents a puzzle.";
cout<< endl; 
cout<<"After Selection, you will see a word. Type it in its unjumbled form.";
cout<< endl;
cout<< "Type a number!";
cout<< endl;
cin>> x;

if (x==1){
cout<< endl;
cout<< "Your word is: bthabtu";
cout<< endl;
cin>> YourAnswer;}
if (YourAnswer=="bathtub"){
	cout<< endl;
	cout<< "You are correct!";
	cout<< endl;}
		
	else {
	cout<<	"WRONG! Program Abort!";
	return 0;
	}

	
	cout<< "Want to try the next level? Type y/n!";
	cout<<endl;
	cin>>Continue;
	if (Continue=="y"){
		x=x+1;
	}
	if (Continue=="n"){
		cout<< "Thanks for playing. You left off on Level "<<x<<".";
		return 0;
	}


if (x==2){
cout<< endl;
cout<< "Your word is: ttpaoo";
cout<<endl;
cin>> YourAnswer;}
if (YourAnswer=="potato"){
	cout<<endl;
	cout<<"You are correct!";
	cout<<endl;}
	
	else {
		cout<< "WRONG! Program Abort!";
		return 0;
	}
	cout<< "Want to try the next level? Type y/n!";
	cout<<endl;
	cin>>Continue;
	if (Continue=="y"){
		x=x+1;
	}
	if (Continue=="n"){
		cout<< "Thanks for playing. You left off on Level "<<x<<".";
		return 0;
	}
	
	
	
if (x==3){cout<< endl;
cout<< "Your word is: skean";
cout<<endl;
cin>> YourAnswer;}
if (YourAnswer=="snake"){
	cout<<endl;
	cout<<"You are correct!";
	cout<<endl;}
	
	else {
		cout<< "WRONG! Program Abort!";
		return 0;
	}
	cout<< "Want to try the next level? Type y/n!";
	cout<<endl;
	cin>>Continue;
	if (Continue=="y"){
		x=x+1;
	}
	if (Continue=="n"){
		cout<< "Thanks for playing. You left off on Level "<<x<<".";
		return 0;
	}
	
	
	
	
	if (x==4){cout<< endl;
cout<< "Your word is: trpeoet";
cout<<endl;
cin>> YourAnswer;}
if (YourAnswer=="treetop"){
	cout<<endl;
	cout<<"You are correct!";
	cout<<endl;}
	
	else {
		cout<< "WRONG! Program Abort!";
		return 0;
	}
	cout<< "Want to try the next level? Type y/n!";
	cout<<endl;
	cin>>Continue;
	if (Continue=="y"){
		x=x+1;
	}
	if (Continue=="n"){
		cout<< "Thanks for playing. You left off on Level "<<x<<".";
		return 0;
	}
}
1
2
3
4
5
if (x==1){
cout<< endl;
cout<< "Your word is: bthabtu";
cout<< endl;
cin>> YourAnswer;}


You have a brace after the YourAnswer input, so that ends that If statement. It then goes to

1
2
3
4
5
6
7
8
9
if (YourAnswer=="bathtub"){
	cout<< endl;
	cout<< "You are correct!";
	cout<< endl;}
		
	else {
	cout<<	"WRONG! Program Abort!";
	return 0;
	}


Since they haven't answered "bathtub", it'll go to the Else, which is the "WRONG.." message.

I got rid of of the braces after YourAnswer. Now it can access one and two. Not three and four...

Code:

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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include <iostream>

int main(){
using namespace std;
int x;
int y ;
string YourAnswer;
string Continue;
cout<<"Welcome to Jumble!";
cout<< endl;
cout<<"We have over 3 words to unjumble!";
cout<< endl;
cout<<"Select a number. Each number represents a puzzle.";
cout<< endl; 
cout<<"After Selection, you will see a word. Type it in its unjumbled form.";
cout<< endl;
cout<< "Type a number!";
cout<< endl;
cin>> x;

if (x==1){
cout<< endl;
cout<< "Your word is: bthabtu";
cout<< endl;
cin>> YourAnswer;
if (YourAnswer=="bathtub"){
	cout<< endl;
	cout<< "You are correct!";
	cout<< endl;}
		
	else {
	cout<<	"WRONG! Program Abort!";
	return 0;
	}

	
	cout<< "Want to try the next level? Type y/n!";
	cout<<endl;
	cin>>Continue;
	if (Continue=="y")
		x=x+1;
	}
	if (Continue=="n"){
		cout<< "Thanks for playing. You left off on Level "<<x<<".";
		return 0;
	}


if (x==2){
cout<< endl;
cout<< "Your word is: ttpaoo";
cout<<endl;
cin>> YourAnswer;
if (YourAnswer=="potato")
	cout<<endl;
	cout<<"You are correct!";
	cout<<endl;}
	
	else {
		cout<< "WRONG! Program Abort!";
		return 0;
	}
	cout<< "Want to try the next level? Type y/n!";
	cout<<endl;
	cin>>Continue;
	if (Continue=="y"){
		x=x+1;
	}
	if (Continue=="n"){
		cout<< "Thanks for playing. You left off on Level "<<x<<".";
		return 0;
	}
	
	
	
if (x==3){
cout<< endl;
cout<< "Your word is: skean";
cout<<endl;
cin>> YourAnswer;
if (YourAnswer=="snake")
	cout<<endl;
	cout<<"You are correct!";
	cout<<endl;}
	
	else {
		cout<< "WRONG! Program Abort!";
		return 0;
	}
	cout<< "Want to try the next level? Type y/n!";
	cout<<endl;
	cin>>Continue;
	if (Continue=="y"){
		x=x+1;
	}
	if (Continue=="n"){
		cout<< "Thanks for playing. You left off on Level "<<x<<".";
		return 0;
	}
	
	
	
	
	if (x==4){
cout<< endl;
cout<< "Your word is: trpeoet";
cout<<endl;
cin>> YourAnswer;
if (YourAnswer=="treetop")
	cout<<endl;
	cout<<"You are correct!";
	cout<<endl;}
	
	else {
		cout<< "WRONG! Program Abort!";
		return 0;
	}
	cout<< "Want to try the next level? Type y/n!";
	cout<<endl;
	cin>>Continue;
	if (Continue=="y"){
	
		x=x+1;}

	if (Continue=="n"){
		cout<< "Thanks for playing. You left off on Level "<<x<<".";}
		return 0;}


You still need the opening brace after the If statements. I just formatted the code a little bit to match up the opening and closing braces. I think you're missing one at the end as well.

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
31
32
33
34
35
36
37
if (x==2)
{
	cout<< endl;
	cout<< "Your word is: ttpaoo";
	cout<<endl;
	cin>> YourAnswer;

	if (YourAnswer=="potato")
		//missing a starting brace for this if compound statement
		cout<<endl;
		cout<<"You are correct!";
		cout<<endl;
	}
	
	else 
	{
		cout<< "WRONG! Program Abort!";
		return 0;
	}
	
	cout<< "Want to try the next level? Type y/n!";
	cout<<endl;
	cin>>Continue;
	
	if (Continue=="y")
	{
		x=x+1;
	}
	if (Continue=="n")
	{
		cout<< "Thanks for playing. You left off on Level "<<x<<".";
		return 0;
	}

}//missing end brace for outer if statement
	
	
Topic archived. No new replies allowed.