// This is in C++
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
bool dmover= false;
bool gunin= false;
bool crmove= false;
while (dmover= false);
int plan;
cout<<"Hello\n";
cout<<"Welcome to the Demo!\n";
cout<<"This is test room 1.\n";
cout<<"You are in a large dusty room, with a table, a gun on the table, and a door to your right."; //Room Description
cout<<"What would you like to do?\n";
cout<<"1) Take the Gun.\n";
cout<<"2) Clean the room.\n";
cout<<"3) Go right (Through the door).\n";
cin>>plan;
if (plan == 1);
{cout<<"You take the gun.\n"};
else {cout<<"Nothing happens\n"};
system("PAUSE");
return EXIT_SUCCESS;
}
Whats wrong here? with my code C++
Your if statement should look more like:
You had a semi-colon after the if (plan == 1) which makes so that if the plan was equal to 1 it would do nothing, and then you had semi-colons after the } instead of after the statements.
if (plan == 1) { cout<<"You take the gun.\n"; } else { cout<<"Nothing happens\n"; }
You had a semi-colon after the if (plan == 1) which makes so that if the plan was equal to 1 it would do nothing, and then you had semi-colons after the } instead of after the statements.
When you have an if() you should have it like this:
You can a ; on the end of the if(), so that means that the if() does nothing, since just a ; means an empty statememt. The second thing is that the { and the } declare a new scope. So you dont put a ; on the end, just like you don't put a ; on the end of ther main() {}. You have to put the ; on the statement, just like you have in the beginning.
P.S. You also have an infinite loop in there:
That's an empty statement, just like I said with the 'if'. You should have it more like:
if(anExpression){ //curly brace 1 //do stuff} //curly brace 2
You can a ; on the end of the if(), so that means that the if() does nothing, since just a ; means an empty statememt. The second thing is that the { and the } declare a new scope. So you dont put a ; on the end, just like you don't put a ; on the end of ther main() {}. You have to put the ; on the statement, just like you have in the beginning.
P.S. You also have an infinite loop in there:
while(dmover == false);
That's an empty statement, just like I said with the 'if'. You should have it more like:
while(dmover == false)//; - not here...{//not here either... //do your stuff ;)}//no here, either...
int main(int argc, char *argv[]){ bool dmover= false; bool gunin= false; bool crmove= false; while (dmover= false); int plan; cout<<"Hello\n"; cout<<"Welcome to the Demo!\n"; cout<<"This is test room 1.\n"; cout<<"You are in a large dusty room, with a table,and a door to your right."; //Room Description cout<<"What would you like to do?\n"; cout<<"1) Take the Gun.\n"; cout<<"2) Clean the room.\n"; cout<<"3) Go right (Through the door).\n"; cin>>plan; if (plan == 1) { cout<<"You take the gun.\n"; } else { cout<<"You are in a large dusty room, with a table,and a door to your right\n"; } if (gunin= true) { cout<<"You are in a large dusty room, with a table,and a door to your right."; } else { cout<<"You are in a large dusty room, with a table,and a door to your right."; }
1) I need to know how I make it, so that when they take the gun, gunnin = true.
2) Is there a way to make it so that it repeats the room description on its own on else. Or do I have to redo the description every time manually?
3) I want the while loop to make it loop forever. Is it the way it should be? If not how do I make it do so. (I need a loop to make the program not stop untill I tell it to(terminate)).
Thanks,
Death
Just a suggestion, if you don't like it ignore this post...
You have if (plan == 1) {/*do stuff*/} else {/*do stuff*/}. But you give 3 choices to the user... The else means that plan != 1... But what if the user puts in something like 5? That wasnt in the choices, so you can do something like this:
Good luck!
You have if (plan == 1) {/*do stuff*/} else {/*do stuff*/}. But you give 3 choices to the user... The else means that plan != 1... But what if the user puts in something like 5? That wasnt in the choices, so you can do something like this:
if (plan == 1) // if the plan is 1{ //do stuff}else if (plan == 2 || plan == 3) // if the plan is the other choices{ //do stuff}else // now... if the choice is not any of them...{ std::cout<<"\n'"<<plan<<"' isn't one of the choices..."<<std::endl;}
Good luck!
Thanks that will help.. (Hadnt thought about that) :)
Still need those other questions answered please. :P
Still need those other questions answered please. :P
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement