game menu problems

  • (2 Pages)
  • +
  • 1
  • 2

29 Replies - 2365 Views - Last Post: 26 September 2010 - 04:29 PM Rate Topic: -----

#16 janotte  Icon User is offline

  • code > sword
  • member icon

Reputation: 990
  • View blog
  • Posts: 5,141
  • Joined: 28-September 06

Re: game menu problems

Posted 25 September 2010 - 06:39 PM

View PostAlex6788, on 26 September 2010 - 10:30 AM, said:

I compiled it with Microsoft Visual C++ 2008 express edition and it works fine.


Turn on the display of warnings in VS. You are writing bad code and not letting the IDE tell you about it.
There is absolutely no way 2 chars can fit into a single char. That's just basic common sense.
If you enable the display of warnings you should get told about that. Something along the line of these messages from GCC
DIC.cpp:32:7: warning: multi-character character constant
DIC.cpp:33:14: warning: multi-character character constant
DIC.cpp: In function ‘int main()’:
DIC.cpp:32: warning: overflow in implicit constant conversion
DIC.cpp:32: error: duplicate case value
DIC.cpp:24: error: previously used here
DIC.cpp:33: warning: overflow in implicit constant conversion
DIC.cpp:33: error: duplicate case value
DIC.cpp:25: error: previously used here



For point of reference line 33 in the posting aligns with line 33 in the above messages.

BTW
Some whitespace is good.
Far too much useless whitespace (as in your posted code) is bad.
You are looking for the Goldilocks of 'just the right amount' of whitespace.
Was This Post Helpful? 0
  • +
  • -

#17 Alex6788  Icon User is offline

  • kitties == adorable


Reputation: 144
  • View blog
  • Posts: 1,667
  • Joined: 15-July 10

Re: game menu problems

Posted 25 September 2010 - 07:07 PM

View Postjanotte, on 25 September 2010 - 07:39 PM, said:

View PostAlex6788, on 26 September 2010 - 10:30 AM, said:

I compiled it with Microsoft Visual C++ 2008 express edition and it works fine.


Turn on the display of warnings in VS. You are writing bad code and not letting the IDE tell you about it.
There is absolutely no way 2 chars can fit into a single char. That's just basic common sense.
If you enable the display of warnings you should get told about that. Something along the line of these messages from GCC
DIC.cpp:32:7: warning: multi-character character constant
DIC.cpp:33:14: warning: multi-character character constant
DIC.cpp: In function ‘int main()’:
DIC.cpp:32: warning: overflow in implicit constant conversion
DIC.cpp:32: error: duplicate case value
DIC.cpp:24: error: previously used here
DIC.cpp:33: warning: overflow in implicit constant conversion
DIC.cpp:33: error: duplicate case value
DIC.cpp:25: error: previously used here



For point of reference line 33 in the posting aligns with line 33 in the above messages.

BTW
Some whitespace is good.
Far too much useless whitespace (as in your posted code) is bad.
You are looking for the Goldilocks of 'just the right amount' of whitespace.

I have warnings enabled so i don't know why I'm not getting any. About the whitespace i know i don't use that much whitespace in my programs that was an example i threw together in the text editor on the website so it was hard to format it. Referring to the "you are writing bad code" i have only used the double letters once before. Thanks for the reply though, now i'll know not to use it in the future.

This post has been edited by Alex6788: 25 September 2010 - 07:08 PM

Was This Post Helpful? 0
  • +
  • -

#18 Alex6788  Icon User is offline

  • kitties == adorable


Reputation: 144
  • View blog
  • Posts: 1,667
  • Joined: 15-July 10

Re: game menu problems

Posted 25 September 2010 - 07:14 PM

View Postsimeesta, on 25 September 2010 - 07:37 PM, said:

Does it run correctly when you enter 'pp' or any of the other characters??

Ahh no it doesn't it just brings up my error message i programmed. I've only used it once before in a program a while back though so i didn't remember that it didn't work.

This post has been edited by Alex6788: 25 September 2010 - 07:15 PM

Was This Post Helpful? 0
  • +
  • -

#19 blaxarbush  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 29
  • Joined: 25-September 10

Re: game menu problems

Posted 25 September 2010 - 08:14 PM

View Postsimeesta, on 25 September 2010 - 05:37 PM, said:

Does it run correctly when you enter 'pp' or any of the other characters??

its still comming up with the same amount of errors no matter if i use numbers or letters. So im done for the night. So i dont know what to do. Thanks for all you help ive done everything that youve suggested and nothing is working. So well yeah.

Thanks for all the help.
Was This Post Helpful? 0
  • +
  • -

#20 simeesta  Icon User is offline

  • Deadly Ninja


Reputation: 219
  • View blog
  • Posts: 592
  • Joined: 04-August 09

Re: game menu problems

Posted 25 September 2010 - 08:21 PM

Post your new code and the errors you are receiving.
Was This Post Helpful? 1
  • +
  • -

#21 Alex6788  Icon User is offline

  • kitties == adorable


Reputation: 144
  • View blog
  • Posts: 1,667
  • Joined: 15-July 10

Re: game menu problems

Posted 25 September 2010 - 09:11 PM

View Postblaxarbush, on 25 September 2010 - 09:14 PM, said:

View Postsimeesta, on 25 September 2010 - 05:37 PM, said:

Does it run correctly when you enter 'pp' or any of the other characters??

its still comming up with the same amount of errors no matter if i use numbers or letters. So im done for the night. So i dont know what to do. Thanks for all you help ive done everything that youve suggested and nothing is working. So well yeah.

Thanks for all the help.

You can use letters just not double letters like pp.
Was This Post Helpful? 1
  • +
  • -

#22 blaxarbush  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 29
  • Joined: 25-September 10

Re: game menu problems

Posted 25 September 2010 - 09:16 PM

its not working either way. I dont know what to do know. but thanks for all your help man.

Heres the code now with only one error.
#include<iostream>
#include<vector>
#include<algorithm>
#include<ctime>
#include<cstdlib>

using namespace std;

int game();
int main()

{
	int yourHealth = 100;
	int oppHealth = 100;
	int yourAttack;
	int oppAttack;

	srand((unsigned int)time(0));

	while(yourHealth > 0 && oppHealth > 0);
	{
		cout << "Your health: " << yourHealth << endl;
		cout << "opponent's health: " << oppHealth << endl << endl;
		system("PAUSE");
		system("CLS");
		
		yourAttack = rand() % 5 + 6;
		oppAttack = rand() % 5 + 6;

		cout << "you hit for " << yourAttack << endl;
		cout << "your opponent hit for " << oppAttack << endl;

		yourHealth -= oppAttack;
		oppHealth -= yourAttack;
		
		system("PAUSE");
		system("CLS");


	}
	if(yourHealth <= 0 && oppHealth <= 0)
		cout << "A double knockout!" << endl;
	else if(yourHealth > 0)
		cout << "you won! Congrats at winning something that took no skill you are now stupid for playing" << endl;
	else
		cout << "You Lose....and really suck at life" << endl;
	
	
{
	cout << "Menu\n\n";
	cout << "P - 1 player\n";
	cout << "PP - 2 player\n";
	cout << "H - High Scores\n";
	cout << "E - Exit\n\n";


	char choice;
	cout << "Choice: ";
	cin >> choice;

	switch (choice)
	{
	case 'p':
        case 'P':
             {	
			cout << "Your the only one\n";
			game();//call the game function

              }
			break;
	case 'pp':
        case 'PP':
 
                {	
			cout << "2 players it is.\n";

                 }
			break;
	case 'h':
        case 'H': // so lowercase h can be entered and uppercase a you can also use toupper() google it.
                
                   {	
			cout << "High scores.\n";

                    }
			break;
                  

        case 'e':
        case 'E':
  
            {
             
           cout << "Exiting..." << endl;
 
            }
        break;

	default:
                 {
			cout << "You made an illegal choice.\n";

                 }

        break;
	}

	cout << endl;

	cin.ignore(); 
	cin.get();
}




this is the error:

Error 1 error C1075: end of file found before the left brace '{' at 'c:\users\brigham bush\documents\c++\gamer\gamer\game.cpp(12)' was matched c:\users\brigham bush\documents\c++\gamer\gamer\game.cpp Line 113

This post has been edited by blaxarbush: 25 September 2010 - 09:17 PM

Was This Post Helpful? 0
  • +
  • -

#23 janotte  Icon User is offline

  • code > sword
  • member icon

Reputation: 990
  • View blog
  • Posts: 5,141
  • Joined: 28-September 06

Re: game menu problems

Posted 25 September 2010 - 09:23 PM

1 - 2 chars into 1? Does that make sense? Why are you doing it?

2 - What is the opening brace on line 49 for? Where is it's its matching closing brace?

EDIT - fix spelling

This post has been edited by janotte: 25 September 2010 - 10:07 PM

Was This Post Helpful? 1
  • +
  • -

#24 ishkabible  Icon User is offline

  • spelling expret
  • member icon




Reputation: 1622
  • View blog
  • Posts: 5,709
  • Joined: 03-August 09

Re: game menu problems

Posted 25 September 2010 - 09:28 PM

you have a mismatched bracket, you need one more at the end, you cant use double letters like 'pp' you need to just use one. also game is undefined so you cant call it. that should get you going :)

edit: look at line 20, your while loop dose nothing, also whats going on on line 46?

This post has been edited by ishkabible: 25 September 2010 - 09:31 PM

Was This Post Helpful? 1
  • +
  • -

#25 simeesta  Icon User is offline

  • Deadly Ninja


Reputation: 219
  • View blog
  • Posts: 592
  • Joined: 04-August 09

Re: game menu problems

Posted 26 September 2010 - 05:20 AM

I think you missed the point about functions.
e.g.

main.cpp

int game();
int highscores();

int main()
{
   //menu code here;
   // call game function game() and highscores() in the switch statement.; etc.
}


game.cpp
int game()
{
   //game code here (the while loop)
}


highscores.cpp
int highscores()
{
  //highscores code here
}



you could use one source file by copying the functions to after main in the same file, but from your original post it appears you were trying to use multiple source files.

Hope this helps.

This post has been edited by simeesta: 26 September 2010 - 05:26 AM

Was This Post Helpful? 1
  • +
  • -

#26 blaxarbush  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 29
  • Joined: 25-September 10

Re: game menu problems

Posted 26 September 2010 - 11:02 AM

Ok now everything is working so much better thank you everyone for helping me out. But there is still one error that i believe is not with the code but it still comes up in the error box. its error LNK1561: entry point must be defined. then under the file tab is says LINK. Now i dont know whatt this means. ive googled it and it says some about the location file and adding a \ but that doesnt work. any suggestions
Was This Post Helpful? 0
  • +
  • -

#27 simeesta  Icon User is offline

  • Deadly Ninja


Reputation: 219
  • View blog
  • Posts: 592
  • Joined: 04-August 09

Re: game menu problems

Posted 26 September 2010 - 11:31 AM

Is your main function defined?
Error

This post has been edited by simeesta: 26 September 2010 - 11:34 AM

Was This Post Helpful? 0
  • +
  • -

#28 simeesta  Icon User is offline

  • Deadly Ninja


Reputation: 219
  • View blog
  • Posts: 592
  • Joined: 04-August 09

Re: game menu problems

Posted 26 September 2010 - 01:45 PM

Spoiler


Spoiler

This post has been edited by simeesta: 26 September 2010 - 01:46 PM

Was This Post Helpful? 1
  • +
  • -

#29 blaxarbush  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 29
  • Joined: 25-September 10

Re: game menu problems

Posted 26 September 2010 - 03:30 PM

View Postsimeesta, on 26 September 2010 - 12:45 PM, said:

Spoiler


Spoiler


thanks man for all the help. i wasnt expecting you do all that for me. I greatly appreciate it. thanks a million
Was This Post Helpful? 0
  • +
  • -

#30 simeesta  Icon User is offline

  • Deadly Ninja


Reputation: 219
  • View blog
  • Posts: 592
  • Joined: 04-August 09

Re: game menu problems

Posted 26 September 2010 - 04:29 PM

You got the general idea, I just reordered it slightly, but i'd look over the code just to make sure you understand it fully - mainly functions. Any questions just ask.
Was This Post Helpful? 1
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2