• ### Announcements

#### Archived

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

# A BIG error

## 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
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 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.

##### Share on other sites
quote:
Original post by Dactylos

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.

thanks for that Dactylos, that was stupid on my part, forgot about that.

quote:
Original post by Mage_gr

Mage_gr, maybe I can clear this up a bit for you. People say that a text based game would be a good idea for a beginner because it helps get you used to the structure and format of a game without have to deal with all the really tough graphics stuff. (I also think its good because it makes you realize that a game isn''t just the graphics, but it is really made by the story.) However, they generally recommend this with the expectation that you already have at least a basic understanding of the language. I''m not trying to discourage you from trying to make games or anything, but you will be much more successful if you get through and understand a ''regular'' programming book or tutorials first. You should most definitely continue this current project, but take a break from it for a while, learn the rest of the language, then come back to the game. You will then see that the errors you made are generally easy to find if you know what is going on.

Like I said, I''m not trying to discourage you but really do some more basic stuff first. We are all happy to guide you in that process. People are probably giving you conflicting advice because they are coming into the discussion at different times. I''ve responded to your previous posts and so I know what has been going on. However, people who haven''t read your previous posts may just be assuming that you have a good understanding of c/c++, and so giving you advice that may be making you overextend yourself.

Sorry for the somewhat lengthy post, but I hope that this is helpful. If you have any questions or anything, please come back. Also, if you want to discuss this further or have any other questions, I would be happy to help. You can reach me at echeslack@hotmail.com.

ewen

##### Share on other sites
quote:
Original post by Jason Zelos

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

A syntax error is basicly a spelling mistake.

,Jay

...You know, C++ ignores Whitespace...

"I''ve learned something today: It doesn''t matter if you''re white, or if you''re black...the only color that really matters is green"
-Peter Griffin

##### Share on other sites
check out www.gametutorials.com,

There are is a tutorial on making a text based game also tutorials on openl, directx ,c/c++, etc. A very great site.

-----------------------------
"There are ones that say they can and there are those who actually do."

"...u can not learn programming in a class, you have to learn it on your own."

[edited by - cMADsc on March 23, 2002 1:11:58 AM]

##### Share on other sites
quote:
Original post by matrix2113
...You know, C++ ignores Whitespace...

True, but this board doesn''t necessarily. Furthermore, usewhitespacetoenhancereadability.

Nuff said on that.

Mage_gr, you can''t make a game in a language you don''t know. Period. cout isn''t a function, it''s an object, and operator << is the function you call on it - made possible through the C++ feature of operator overloading. That means you''re not forced to write it closely packed (cout<<) but can space it out instead (cout <<). Also, you can insert several values and strings into cout at once, and you can format them freely:
cout << "A double:     " << d // insert a double     << "\nA float:    " << f // insert a float     << "\nAn integer: " << i // insert an integer     << endl;

Stop for a while and write simple programs to learn the basics of the language, and then try to write a text game. So show us what simple programs you''ve written and let us help you learn the language with those.

[ GDNet Start Here | GDNet Search Tool | GDNet FAQ | MS RTFM [MSDN] | SGI STL Docs | Google! ]
Thanks to Kylotan for the idea!

##### Share on other sites
I have written simple programs copied from the book: Learn C++ in 10 minutes by Jesse Liberty(without copy and paste).Unfortunately as I said it really confuses me there with the pointers and references in classes.I think I don''t understand because it doesn''t have good examples.(It always give one with a cat).Also I want to ask something about forums.Whenever Oluseyi post something it sais next to the name moderator.Why is this?

##### Share on other sites
Moderator - Someone who can edit posts by everybody if they are being an ass, it happens in all forums. But I think the supreme-admin type people on the forums are the staff here. The green one.

##### Share on other sites
Also, make sure your file is .cpp not .c

##### Share on other sites
quote:
Original post by Mage_gr
I have written simple programs copied from the book: Learn C++ in 10 minutes by Jesse Liberty(without copy and paste).Unfortunately as I said it really confuses me there with the pointers and references in classes.I think I don''t understand because it doesn''t have good examples.(It always give one with a cat).Also I want to ask something about forums.Whenever Oluseyi post something it sais next to the name moderator.Why is this?

If you''re just copying programs out of the book, you obviously aren''t doing much. You need to actually understand what you read. Whenever you learn something new, you should be able to write your own simple programs to try stuff out with it, don''t just copy stuff from the book. If you don''t understand something, either re-read that section in the book or do a search for topics related to the thing you''re having trouble with.

##### Share on other sites
I understand everything so far and have made some simple programs of my own but I am stuck in pointers right now.I can not understand them.

##### Share on other sites
quote:
Original post by Mage_gr
I understand everything so far and have made some simple programs of my own but I am stuck in pointers right now.I can not understand them.

There are plenty of tutorials on pointers out on the net. Go to Google and start looking.

Also, I found this at cplusplus.com, it seems like it covers pointers well enough, but I didn't actually read through the whole thing. You might want to check it out.

[edited by - SilentCoder on March 23, 2002 9:07:56 AM]

##### Share on other sites
Don''t take this the wrong way, but if you are having trouble with switch statements and text streams, not to mention recognising error statments and correcting simple syntax bugs, then jumping to pointers is not the best idea.

Learn what you are doing now before you change topics, its quicker in the long run.

,Jay

##### Share on other sites

#include <iostream>
#include <string>

put this:

#include <iostream.h>
#include <string.h>

I''m not sure of any other errors but those are the biggies!

I''''m a beginner in C++ ^_^

##### Share on other sites
Always try to think of where the errors are coming from.

For example:

error C2065: ''You'' : undeclared

You typed:
cout<<"You are in a locked room full of stores for the soldiers.What are you going to do?\n";

You used the function ''cout'' which is declared in the library ''iostream'' which is pointed to by ''iostream.h'' which is a ''header file''. Except you didn''t type ''iostream.h'' so the compiler didn''t know what the hell ''cout<<"You are in a locked room full of stores for the soldiers.What are you going to do?\n";'' meant. This is the cause of the 80 errors.

Sorry for over explaining. But I hope this helps!

##### Share on other sites
quote:
Original post by Fireberg 2k

#include <iostream>
#include <string>

put this:

#include <iostream.h>
#include <string.h>

I'm not sure of any other errors but those are the biggies!

I'm a beginner in C++ ^_^

Actually <iostream> and <string> are the proper names, iostream.h is a backwards-compatibility header, and is not guaranteed to exist. string.h contains C functions for manipulating char-arrays. The file 'string' contains the std::string class (in C++ you should use 'cstring' instead of string.h if you need char-array manipulation functions).

(This is, of course, assuming that your compiler is reasonably standards compliant.)

[edited by - Dactylos on March 24, 2002 9:07:52 PM]

##### Share on other sites
quote:
Original post by Mage_gr
I have written simple programs copied from the book: Learn C++ in 10 minutes by Jesse Liberty

I''ve heard Very Bad Things about Liberty''s books. I''d recommend you to get another book.

Fireberg 2k: Your explanation is completely wrong.

[ GDNet Start Here | GDNet Search Tool | GDNet FAQ | MS RTFM [MSDN] | SGI STL Docs | Google! ]
Thanks to Kylotan for the idea!