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!
#include <iostream>
int main(){
usingnamespace 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;
}
}
#include <iostream>
int main(){
usingnamespace 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.
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