|
-
December 4th, 2008, 02:02 PM
#1
What's wrong with this??
So i'm making a stupid little game( i'm a beginner)
I want to make it so that if the user inputs something wrong it will just loop back around, so they can enter it again.
Code:
int whereToGo;
do {
cin >> whereToGo;
if(whereToGo == 1); {
cout << " You go outside and you are stopped by a guard.\n";
cout << " He asks you to go on a quest for him";
}
else {
if(whereToGo == 2);
cout << " You have chosen to stay and look around\n";
cout << " You look around the castle is made of marble\n";
cout << " There are wealthy people all around you\n";
}
} while (whereToGo < 3);
any suggestions are welcome thanks
-
December 4th, 2008, 02:20 PM
#2
Re: What's wrong with this??
if(whereToGo == 1);
Your braces don't look right in your else and second if statement either.
Last edited by GCDEF; December 4th, 2008 at 02:23 PM.
-
December 4th, 2008, 02:30 PM
#3
Re: What's wrong with this??
Grr i tried to fix it but i still don't get it :P
-
December 4th, 2008, 02:34 PM
#4
Re: What's wrong with this??
 Originally Posted by jesus45
Grr i tried to fix it but i still don't get it :P
What did you try? I assume you got the point that your if statements shouldn't be terminated with a semi-colon?
-
December 4th, 2008, 02:36 PM
#5
Re: What's wrong with this??
this is what i have now.
Code:
int whereToGo;
do {
cin >> whereToGo;
if(whereToGo == 1);
cout << " You go outside and you are stopped by a guard.\n";
cout << " He asks you to go on a quest for him";
}
else
if(whereToGo == 2);
cout << " You have chosen to stay and look around\n";
cout << " You look around the castle is made of marble\n";
cout << " There are wealthy people all around you\n";
} while (whereToGo < 3);
Still doing something wrong though.
-
December 4th, 2008, 02:46 PM
#6
Re: What's wrong with this??
 Originally Posted by jesus45
this is what i have now.
Code:
int whereToGo;
do {
cin >> whereToGo;
if(whereToGo == 1);
cout << " You go outside and you are stopped by a guard.\n";
cout << " He asks you to go on a quest for him";
}
else
if(whereToGo == 2);
cout << " You have chosen to stay and look around\n";
cout << " You look around the castle is made of marble\n";
cout << " There are wealthy people all around you\n";
} while (whereToGo < 3);
Still doing something wrong though.
Again - sigh - don't put a semi-colon after your if statement.
Anything you want to execute if the if statement is true should be enclosed in a block using braces.
Code:
if(whereToGo == 1)
{
cout << " You go outside and you are stopped by a guard.\n";
cout << " He asks you to go on a quest for him";
}
-
December 9th, 2008, 04:11 AM
#7
Re: What's wrong with this??
int whereToGo;
while ((whereToGo !=1) || (whereToGo!=2))
{
cout<<"Enter I/p"<<endl;
cin >> whereToGo;
if(whereToGo == 1)
{
cout << " You go outside and you are stopped by a guard.\n";
cout << " He asks you to go on a quest for him";
break;
}
else {
if(whereToGo == 2)
{
cout << " You have chosen to stay and look around\n";
cout << " You look around the castle is made of marble\n";
cout << " There are wealthy people all around you\n";
break;
}
}
}
-
December 9th, 2008, 08:07 AM
#8
Re: What's wrong with this??
((whereToGo !=1) || (whereToGo!=2))
Think about that. See if you can come up with a number where that is never true.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|