A BIG error

Started by
62 comments, last by Mage_gr 22 years ago
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<<You move south\n"; current_room=START; } else { cout<<"You can''t go in that direction.\n"; } break; case YARD: break; default: break; } } int main() { while(run_game) { display_description(); int input=get_input(); if(input!=QUIT) move_player(input); else run_game=false; } } The errors are: C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(20) : error C2065: ''You'' : undeclared identifier C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(20) : error C2146: syntax error : missing '';'' before identifier ''are'' C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(20) : error C2065: ''are'' : undeclared identifier C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(20) : error C2146: syntax error : missing '';'' before identifier ''now'' C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(20) : error C2065: ''now'' : undeclared identifier C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(20) : error C2146: syntax error : missing '';'' before identifier ''in'' C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(20) : error C2065: ''in'' : undeclared identifier C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(20) : error C2146: syntax error : missing '';'' before identifier ''the'' C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(20) : error C2065: ''the'' : undeclared identifier C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(20) : error C2146: syntax error : missing '';'' before identifier ''Prison'' C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(20) : error C2065: ''Prison'' : undeclared identifier C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(20) : error C2146: syntax error : missing '';'' before identifier ''yard'' C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(20) : error C2065: ''yard'' : undeclared identifier C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(20) : error C2146: syntax error : missing '';'' before identifier ''and'' C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(20) : error C2065: ''and'' : undeclared identifier C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(20) : error C2146: syntax error : missing '';'' before identifier ''when'' C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(20) : error C2065: ''when'' : undeclared identifier C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(20) : error C2146: syntax error : missing '';'' before identifier ''you'' C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(20) : error C2065: ''you'' : undeclared identifier C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(20) : error C2146: syntax error : missing '';'' before identifier ''reach'' C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(20) : error C2065: ''reach'' : undeclared identifier C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(20) : error C2146: syntax error : missing '';'' before identifier ''the'' C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(20) : error C2146: syntax error : missing '';'' before identifier ''door'' C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(20) : error C2065: ''door'' : undeclared identifier C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(20) : error C2146: syntax error : missing '';'' before identifier ''which'' C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(20) : error C2065: ''which'' : undeclared identifier C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(20) : error C2146: syntax error : missing '';'' before identifier ''leads'' C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(20) : error C2065: ''leads'' : undeclared identifier C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(20) : error C2146: syntax error : missing '';'' before identifier ''to'' C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(20) : error C2065: ''to'' : undeclared identifier C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(20) : error C2146: syntax error : missing '';'' before identifier ''the'' C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(20) : error C2146: syntax error : missing '';'' before identifier ''outer'' C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(20) : error C2065: ''outer'' : undeclared identifier C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(20) : error C2146: syntax error : missing '';'' before identifier ''base'' C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(20) : error C2065: ''base'' : undeclared identifier C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(20) : error C2146: syntax error : missing '';'' before identifier ''you'' C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(20) : error C2146: syntax error : missing '';'' before identifier ''notice'' C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(20) : error C2065: ''notice'' : undeclared identifier C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(20) : error C2146: syntax error : missing '';'' before identifier ''it'' C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(20) : error C2065: ''it'' : undeclared identifier C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(20) : error C2146: syntax error : missing '';'' before identifier ''requires'' C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(20) : error C2065: ''requires'' : undeclared identifier C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(20) : error C2146: syntax error : missing '';'' before identifier ''a'' C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(20) : error C2065: ''a'' : undeclared identifier C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(20) : error C2146: syntax error : missing '';'' before identifier ''password'' C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(20) : error C2065: ''password'' : undeclared identifier C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(20) : error C2228: left of ''.Thank'' must have class/struct/union type C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(20) : error C2146: syntax error : missing '';'' before identifier ''god'' C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(20) : error C2065: ''god'' : undeclared identifier C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(20) : error C2146: syntax error : missing '';'' before identifier ''it'' C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(20) : error C2146: syntax error : missing '';'' before identifier ''gives'' C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(20) : error C2065: ''gives'' : undeclared identifier C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(20) : error C2146: syntax error : missing '';'' before identifier ''you'' C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(20) : error C2146: syntax error : missing '';'' before identifier ''a'' C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(20) : error C2146: syntax error : missing '';'' before identifier ''hint'' C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(20) : error C2065: ''hint'' : undeclared identifier C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(20) : error C2228: left of ''.The'' must have class/struct/union type C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(20) : error C2146: syntax error : missing '';'' before identifier ''hint'' C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(20) : error C2146: syntax error : missing '';'' before identifier ''is'' C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(20) : error C2065: ''is'' : undeclared identifier C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(20) : error C2059: syntax error : ''bad suffix on number'' C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(20) : error C2146: syntax error : missing '';'' before identifier ''Which'' C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(20) : warning C4552: ''-'' : operator has no effect; expected operator with side-effect C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(20) : error C2065: ''Which'' : undeclared identifier C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(20) : error C2146: syntax error : missing '';'' before identifier ''is'' C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(20) : error C2146: syntax error : missing '';'' before identifier ''the'' C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(20) : error C2146: syntax error : missing '';'' before identifier ''password'' C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(21) : error C2059: syntax error : ''break'' C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(32) : error C2143: syntax error : missing '')'' before ''return'' C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(51) : warning C4553: ''=='' : operator has no effect; did you intend ''=''? C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(61) : error C2146: syntax error : missing '';'' before identifier ''move'' C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(61) : error C2017: illegal escape sequence C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(61) : error C2065: ''move'' : undeclared identifier C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(61) : error C2146: syntax error : missing '';'' before identifier ''south'' C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(61) : error C2001: newline in constant C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(61) : error C2065: ''south'' : undeclared identifier C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(61) : error C2146: syntax error : missing '';'' before identifier ''n'' C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(61) : error C2065: ''n'' : undeclared identifier C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(61) : error C2143: syntax error : missing '';'' before ''string'' C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(62) : error C2146: syntax error : missing '';'' before identifier ''current_room'' C:\Program Files\Microsoft Visual Studio\MyProjects\thegame1\gamea.cpp(86) : warning C4508: ''main'' : function should return a value; ''void'' return type assumed Error executing cl.exe. thegame1.exe - 78 error(s), 3 warning(s)
When you see a roller coaster, get on it,put your hands in the air,and ride it to the very end.Life doesn't remember you unless you kick,scream,and claw your way to the top.There is nothing in the world that is impossible.If you believe that you can do it, you will.
Advertisement
Try adding spaces,

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

A syntax error is basicly a spelling mistake.

,Jay
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.
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).
It was the readabilty I meant it for.

The line that read

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


The begining is probably missing ".

,Jay
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.
--- krez ([email="krez_AT_optonline_DOT_net"]krez_AT_optonline_DOT_net[/email])
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
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( );

~CGameProgrammer( );Developer Image Exchange -- New Features: Upload screenshots of your games (size is unlimited) and upload the game itself (up to 10MB). Free. No registration needed.
I was adviced to start a text game with the knowledge I had.In the start I was doing well.Then I was agian adviced not to use so many if and else statements but use it like the way it is up there.My book really messes it up there with the pointers and as you can understand I am a little confused.Also because now that I started I can''t just give up on it.The code above was not written bt me but by someone from this site who adviced me.But although I understood some of it I didn''t understand what std and all these stuff are.Also I don''t understand how I cna make it gi frim one room to another.Please someone reply and help me.Also please don''t add comments like this is not for your levele.t.c. because others say it is and others it is not...thing which confuses me more
When you see a roller coaster, get on it,put your hands in the air,and ride it to the very end.Life doesn't remember you unless you kick,scream,and claw your way to the top.There is nothing in the world that is impossible.If you believe that you can do it, you will.
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]
before your code, and add:
[ /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.

This topic is closed to new replies.

Advertisement