Jump to content
  • Advertisement
Sign in to follow this  
text based fun

Need help with c++ for text adventure game

This topic is 4861 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

Hey everyone I'm new with c++ and ive done some online tutorials the version of c++ i have is dev-c++ from bloodshed.net. I can only get one question done and when i try to program another one in and i try and compile and run i get a whole bunch of error messages and wont compile and run. #include <iostream> using namespace std; int main(){ char myArray[50]; cout << "wanna play a game? "; cin.getline( myArray, 50, '\n'); if( !strcmp( myArray, "yes")){ strcat( myArray, "good thats what I thought\n"); } else { strcpy( myArray, "Oh really thats to bad!\n"); } } #include <iostream> using namespace std; int main(){ cout << "It was early in the morning on a cold winters day you get out of bed and have a huge hangover\n"; system("pause"){; } This is what i have so far and i need help because i just started programming and i dont know what to do any suggestions would be gladly accepted.

Share this post


Link to post
Share on other sites
Advertisement
You can't just do both of them in the same file. You need to comment the first one out or delete it before creating another one.

This is because there can only be one main() function in a program.

Share this post


Link to post
Share on other sites
Well i dont have aim so ohwell and i should prolly mention the

include <iostream> at the bottom is my signature and not part of the actual code if anybody else can help me please do

Share this post


Link to post
Share on other sites
Quote:
Original post by text based fun
I'm so confused could you please help me more than just saying that like describe it more because i am a complete and total nOOber cake

thank you please


Not sure I can be much clearer... but I'll try.

Your post was the first two programs, right? If they are both typed into the same file, then that is your problem. If you delete the code for the first program before writing the second one, then it will work again.

The problem is that there can only be one program in a C++ file. If you have two (such is the case with your two main() functions) then the compiler will get confused.

Just remove the code for the first program.

About as clear as I can be, hope it helps...

Share this post


Link to post
Share on other sites
No offense, but I think you should either read up more on those tutorials or, preferrably, get a good book on C++. Explaining these errors in a way that'll teach you not to make them (or other similar mistakes) again is kind of hard when you don't have a basic level of knowledge of the language.
Learning by doing is great, but I think you should combine the doing with a little more reading.

Quote:
Original post by JBourrie
Not sure I can be much clearer... but I'll try.

Your post was the first two programs, right? If they are both typed into the same file, then that is your problem. If you delete the code for the first program before writing the second one, then it will work again.

The problem is that there can only be one program in a C++ file. If you have two (such is the case with your two main() functions) then the compiler will get confused.

Just remove the code for the first program.

About as clear as I can be, hope it helps...
The way I understood it, he wants the code of the second program to execute immediately after the first.

Share this post


Link to post
Share on other sites
Yeah all I really want for it to do is ask one question after another but also have some story writen in the middle of it also

one more thing so you want me to save the orriginal one then make another one for the second one then compile them together? if so how do i do that.

the online tutorial i was reading was not good so i have stoped reading it and im looking for more any suggestions?

Share this post


Link to post
Share on other sites
Ok, I misunderstood what you were doing. I thought you were doing two separate "test" programs.

I agree with the previous poster, though, that you should have a basic grasp of the language before attempting a game.

There still can only be one main() function, so instead of having two different main()'s, the second "question" should just come after the first one inside the same main() function. If that was not clear, you should go back into your C++ tutorials until you are comfortable with that.

Share this post


Link to post
Share on other sites
Thank you guys for all your help I still have the problum but have learned something while doing so.

what books would you recomend for a noob like me some one told me "learn c++ in 21 days" was a good one but cant remember if that was the correct book name

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!