Public Group

#### Archived

This topic is now archived and is closed to further replies.

# A BIG error

This topic is 5959 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Sorry to bother you again but when I asked you to give me another code to write in order to avoid the many if statements sabreman gave me the following code.When I compiled it it had 80 errors!!!!Do you have the courage to help me please??? #include <iostream> #include <string> #include <stdlib.h> using namespace std; enum rooms{START,HALL,YARD}; enum actions{QUIT,INVALID,NORTH,EAST,SOUTH,WEST}; int current_room=START; bool run_game= true; void display_description() { switch(current_room) { case START: cout<<"You are in a locked room full of stores for the soldiers.What are you going to do?\n"; break; case HALL: cout<<"Now you are in a hall which gives you the option to choose between two ways.Right or left.Which will you chose?\n"; break; case YARD: cout<> action; if(tolower(action[0])==''n'' return NORTH; if(tolower(action[0])==''e'') return EAST; if(tolower(action[0])==''s'') return SOUTH; if(tolower(action[0])==''w'') return WEST; if(tolower(action[0])==''q'') return QUIT; return INVALID; } void move_player(int direction) { switch(current_room) { case START: if(direction==NORTH) { cout<<"You move north\n"; current_room==HALL; } else { cout<<"You can''t go in that direction.\n"; } break; case HALL: if(direction==SOUTH) { cout<

##### Share on other sites

cout << "This is a string" << endl;

A syntax error is basicly a spelling mistake.

,Jay

##### Share on other sites
Are you sure you posted the whole code? I couldn''t find those identifiers it reported anywhere. Looks to me like you forgot to enclose a string in quotes.

I think this type of project may be a little too complex for you at your current stage, you really need to slow down a little. Wait until you finish learning C++ before you start jumping in and making games. Also, learn how to read your compiler''s errors.

##### Share on other sites
Post the file that has the string ''you are now in the prison yard''. I''m willing to bet it doesn''t have a quote in the front of it (it should).

##### Share on other sites
It was the readabilty I meant it for.

You are now in the prison yard and.....

The begining is probably missing ".

,Jay

##### Share on other sites
why won''t you learn the basics of the language? it will not take very long to get past the beginning, and then you will have much better luck with this game.

##### Share on other sites
it looks like you are missing a < in line 21

should be something like

cout << break;

however i''m not sure what that was supposed to accomplish, i would assume you want something like

cout << "Message goes here\n"; break;

that is probably what breaks the rest of the code.
also, how far are you through your c++ book? are you understanding stuff? does it use cout etc or printf? you need to learn how to debug, but this stuff shouldn''t be to difficult to understand (though I can understand it being misleading because sometimes it doesn''t report exactly what is wrong, like here), but you should be able to look around that section and find what is wrong. if it still doesn''t compile, work at it for a while and try to find errors in the code before coming straight here

ewen

##### Share on other sites
Also he says things like "current_room==HALL" which should be "current_room=HALL". And he has the mysterious line "cout< current_room=START".

~CGameProgrammer( );

##### Share on other sites
Code by Mage_gr:

  	case YARD:			cout<<You are now in the Prison yard and when you reach the door which leads to the outer base you notice it requires a password.Thank god it gives you a hint.The hint is (30*2+90)-60.Which is the password?				break;

You need to enclose that sentence in double quotes ( " ), and the cout-statement needs to be terminated with a semi-colon ( ; ).

  			cout<<You move south\n";

Same thing here, you have no quotation mark to start the sentence.

For those of you who didn''t know this, the board usually mangles text containing < or >, since those are used to write HTML tags. Simply click the ''quote'' or ''edit'' button of a message to view it correctly.

Also a tip to you Mage_gr, click the edit button of your original message and add:
[ source]
[ /source]
after your code, only don''t write any whitespace within the [ and ] brackets. This will put your code in a nice source code box, and should prevent the board from mangling your < > characters.

1. 1
Rutin
25
2. 2
3. 3
JoeJ
18
4. 4
5. 5

• 14
• 11
• 9
• 9
• 10
• ### Forum Statistics

• Total Topics
631754
• Total Posts
3002104
×