Skip to main content
gamedev.net
🔒 Locked

C++ problems

Started by Glomp 4 replies 850+ views
Original Post
Glomp
Glomp
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 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);
mrbastard
mrbastard
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.
[size="1"]
JohnBolton
JohnBolton
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.
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
mrbastard
mrbastard
Quote:
Original post by JohnBolton
To be more effective in your plea for help, you should:
  1. Post only the relevant code.
  2. Post the exact error messages.
  3. 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.

[size="1"]
Alan Kemp
Alan Kemp
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
"There will come a time when you believe everything is finished. That will be the beginning." -Louis L'Amour
Fruny
Fruny
#include "stdafx.h" <strike>int _tmain(int argc, _TCHAR* argv[]){   return 0;}</strike><font color=gold>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.</font>#include <iostream>	<strike><windows.h></strike><font color=lime>#include <windows.h></font><font color=gold>You can't include several files with a single #include.Your current code probably doesn't need <windows.h> anyway.</font>using namespace std;int main() <strike>;</strike><font color=gold>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.</font><font color=lime>{</font>   do    {      int input = <strike>' '</strike> <font color=lime>0</font>;      <font color=gold>' ' is a character, which corresponds to an integer value of 32.      Initializing your variable is laudable, but your choice of initial      value is strange.</font>      cout<<"1.Play Game\n";      cout<<"2.Play Multiplayer\n";      cout<<"3.Exit\n";      cin>> input;      cin.ignore(); <font color=gold>skip one character? Why?</font>      do       {         system("cls");         int two_input = <strike>' '</strike> <font color=lime>0</font>;         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 ( <font color=lime>two_</font>input == 1 );      <font color=gold>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.</font>   } while ( <strike>two_</strike>input == 3);<font color=lime>}</font> <font color=gold>end of main</font>


"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.