Public Group

# C++ problems

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

## Recommended Posts

I made a simple load menu code using C++ and apparently I needed to use do...while loops to get back to the first menu. Can any of you help me to get this code working, I'm getting errors and I don't know what to do. If my post is stupid or in the wrong section please move it....being a new person is dumb lol. Thanks in advance, Glomp. Code: #include "stdafx.h" int _tmain(int argc, _TCHAR* argv[]) { return 0; } #include <iostream> <windows.h> using namespace std; int main(); do { int input = ' '; cout<<"1.Play Game\n"; cout<<"2.Play Multiplayer\n"; cout<<"3.Exit\n"; cin>> input; cin.ignore(); do { system("cls"); int two_input = ' '; cout<<"Select!\n"; cout<<"1.New Game\n"; cout<<"2.Load Game\n"; cout<<"3.Return to Start\n"; cin>> two_input; cin.ignore(); } while ( input == 1 ); } while ( two_input == 3);

##### Share on other sites
It's a little unclear exactly what you want it to do. Perhaps you could write it in plain english, then we can see how the code differs from your intention. Also, read the forum FAQ for how to use src tags - makes it easier to read for people wanting to help.

##### Share on other sites
To be more effective in your plea for help, you should:
1. Post only the relevant code.
2. Post the exact error messages or describe the specific problem very clearly and succinctly.
3. Show exactly where the errors or problems occur.
4. Use [ code ] [ / code ] or [ source ] [ / source ] tags.

##### Share on other sites
Quote:
 Original post by JohnBoltonTo be more effective in your plea for help, you should:Post only the relevant code.Post the exact error messages.Show exactly where the errors occur.

I think it's a logic problem, not a syntax one. I think he's still learning flow control.

##### Share on other sites
There is so much wrong with this I really dont know where to start...

Include only takes a single file. If you want to include more than one, use multiple include's

// BAD#include <iostream> <windows.h>// GOOD#include <iostream>#include <windows.h>

Your code needs to be in a function. Presumably you want it all in your main(). Why do you have _tmain()? If thats really your entry point then substitute that for main in the following.

The general structure should be something like this:

int main(){    // your code   return 0;}

If you make those changes I think you still have logic errors, but you should have code that compiles. Start with just the first menu, get that working then add the second menu. Also you might want to think about making seperate functions to display each of the menus. It will make your code a lot clearer.

Alan

##### Share on other sites
#include "stdafx.h" int _tmain(int argc, _TCHAR* argv[]){   return 0;}You can't have both main() and _tmain()._tmain is a macro that is used for Unicode-aware programs.Don't bother with it for now.#include <iostream>	<windows.h>#include <windows.h>You can't include several files with a single #include.Your current code probably doesn't need <windows.h> anyway.using namespace std;int main() ;If you put a semicolon there, you are declaring main, notdefining it. It means you are telling the compiler "there is afunction called 'main'." instead of telling it what the functioncontains.{   do    {      int input = ' ' 0;      ' ' is a character, which corresponds to an integer value of 32.      Initializing your variable is laudable, but your choice of initial      value is strange.      cout<<"1.Play Game\n";      cout<<"2.Play Multiplayer\n";      cout<<"3.Exit\n";      cin>> input;      cin.ignore(); skip one character? Why?      do       {         system("cls");         int two_input = ' ' 0;         cout<<"Select!\n";         cout<<"1.New Game\n";         cout<<"2.Load Game\n";         cout<<"3.Return to Start\n";	 cin>> two_input;         cin.ignore();      } while ( two_input == 1 );      You've got to make sure the loop's code can affect the loop      condition. If you read into two_input but check input, nothing      good will happen.   } while ( two_input == 3);} end of main

1. 1
Rutin
22
2. 2
3. 3
4. 4
5. 5

• 9
• 9
• 9
• 14
• 12
• ### Forum Statistics

• Total Topics
633306
• Total Posts
3011287
• ### Who's Online (See full list)

There are no registered users currently online

×