Jump to content
  • Advertisement
Sign in to follow this  
Glomp

C++ problems

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

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


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


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


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

Share this post


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


Link to post
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, not
defining it. It means you are telling the compiler "there is a
function called 'main'." instead of telling it what the function
contains.


{

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


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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!