• Advertisement

Archived

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

A BIG error

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
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

Share this post


Link to post
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]
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.

Share this post


Link to post
Share on other sites

  • Advertisement