Jump to content

c++ game


bkhova211
 Share

Recommended Posts

Hey guys im trying to make this betting game where the user bets a certain amount of money then the computer randomly picks a number and the player has six chances to guess the number. I cant get it to run because of errors, any help would be greatly appreciated. thanks

 

/* ========================================================================== */
/* HEADER FILES */

 #include <iostream>
 #include <ctime>
 #include <cstdlib>
 #include <cmath>
 using namespace std;

// Prototypes
 void Printheading(int money);
 void PrintPayout();
 void GetBet(int money, int& bet);
 int GetGuess(void);
 int CalcNewMoney(int money, int bet, int guesses);
 int PlayAgain(void);
 int PlayGame(int money);
 int Start_Balance = 1000;
 char doagain;
 char Play;
 int noOfGuesses = 0;
 int guess;
 int check;
 int random;
 int GenerateRandomNumber();
 double bank, winnings, total;
 int money = 1000,
		oldmoney = money;

/* ========================================================================== */
/* MAIN FUNCTION */
int main()
{


GenerateRandomNumber();
{
int random;
srand(static_cast<unsigned>(time(NULL)));
random = rand() % 100 + 1;

GetBet(int money, int& bet)
}

PrintPayout();
{
 cout << "If you guess correctly within the first 6 guesses, you will" << endl;
 cout << "win the amount of money you bet divided by the amount of guesses"
	   << endl;
 cout << "If you don't guess correctly within the first 6 guesses you" << endl;
 cout << "lose the money that you bet" << endl;
}

GetGuess(int guess)
{
	 if (guess > random)
			 {
				check = 1;
			 }

	 else if (guess < random)
			 {
				check = -1;
			 }
	 else
			 {
				check = 0;
			 }

return (GetGuess);
}

Playgame()
{
cout << "-----------------------------------------------" << endl;
cout << "Welcome to the High-Low betting game." << endl;
cout << "You have $" << Start_Balance << "to begin the game" << endl;
cout << "Valid guesses are between the numbers 1 and 100" <<endl;
cout << "-----------------------------------------------";

cout << "Would you like to play (y / n)" << endl;
			Bank = 1000.00;
cin >> Play;
		if (Play=='y')
		{
		  winnings = GetBet/noOfGuesses
		  cout << "Great! Your payout will be as follows:" << endl << endl;
		  printPayout();

		  cout << "How money would you like to bet?" << endl;
		  GetBet(int money, int& bet);

  while ((noOfGuesses < 7 ))
  {
	 cout << "Now guess a number between 1 and 100" << endl;
			 cin >> guess;
			 noOfGuesses++;
			 GetGuess(guess);
		 if (GetGuess(guess) == 0)
		 {
	 total = CalcNewMoney;
	 cout << "Correct, you win " << winnings << ", your bank is now " 
		  << CalcNewMoney << endl 
	 cout << "Do You Wanna Play Again?(Y/N)";
	 cin >> play;
	 break;
		 }
		 else if (GetGuess(guess) == -1)
		 {
		 cout << "Sorry too low try higher" << endl;
		 }
		 else if (GetGuess(guess) == 1)
		 {
		 cout << "Sorry too high try lower" << endl;
		 }
  }
		}
}
return 0;
}

Share this post


Link to post
Share on other sites

Can you post the errors you are getting?

 

Thanks for the reply these are the errors:

 

1>c:\documents and settings\bkhova211\my documents\visual studio 2008\projects\hilo\hilo\hilo.cpp(88) : error C2144: syntax error : 'int' should be preceded by ')'

1>c:\documents and settings\bkhova211\my documents\visual studio 2008\projects\hilo\hilo\hilo.cpp(88) : error C2059: syntax error : ')'

1>c:\documents and settings\bkhova211\my documents\visual studio 2008\projects\hilo\hilo\hilo.cpp(104) : error C2146: syntax error : missing ')' before identifier 'guess'

1>c:\documents and settings\bkhova211\my documents\visual studio 2008\projects\hilo\hilo\hilo.cpp(104) : error C2059: syntax error : ')'

1>c:\documents and settings\bkhova211\my documents\visual studio 2008\projects\hilo\hilo\hilo.cpp(116) : error C2065: 'Money' : undeclared identifier

1>c:\documents and settings\bkhova211\my documents\visual studio 2008\projects\hilo\hilo\hilo.cpp(121) : error C2296: '/' : illegal, left operand has type 'void (__cdecl *)(int,int &)'

1>c:\documents and settings\bkhova211\my documents\visual studio 2008\projects\hilo\hilo\hilo.cpp(121) : error C2146: syntax error : missing ';' before identifier 'cout'

1>c:\documents and settings\bkhova211\my documents\visual studio 2008\projects\hilo\hilo\hilo.cpp(122) : error C3861: 'printPayout': identifier not found

1>c:\documents and settings\bkhova211\my documents\visual studio 2008\projects\hilo\hilo\hilo.cpp(125) : error C2144: syntax error : 'int' should be preceded by ')'

1>c:\documents and settings\bkhova211\my documents\visual studio 2008\projects\hilo\hilo\hilo.cpp(125) : error C2660: 'GetBet' : function does not take 0 arguments

1>c:\documents and settings\bkhova211\my documents\visual studio 2008\projects\hilo\hilo\hilo.cpp(125) : error C2059: syntax error : ')'

1>c:\documents and settings\bkhova211\my documents\visual studio 2008\projects\hilo\hilo\hilo.cpp(132) : error C2660: 'GetGuess' : function does not take 1 arguments

1>c:\documents and settings\bkhova211\my documents\visual studio 2008\projects\hilo\hilo\hilo.cpp(133) : error C2660: 'GetGuess' : function does not take 1 arguments

1>c:\documents and settings\bkhova211\my documents\visual studio 2008\projects\hilo\hilo\hilo.cpp(135) : error C2440: '=' : cannot convert from 'int (__cdecl *)(int,int,int)' to 'double'

1> There is no context in which this conversion is possible

1>c:\documents and settings\bkhova211\my documents\visual studio 2008\projects\hilo\hilo\hilo.cpp(138) : error C2146: syntax error : missing ';' before identifier 'cout'

1>c:\documents and settings\bkhova211\my documents\visual studio 2008\projects\hilo\hilo\hilo.cpp(139) : error C2065: 'play' : undeclared identifier

1>c:\documents and settings\bkhova211\my documents\visual studio 2008\projects\hilo\hilo\hilo.cpp(142) : error C2660: 'GetGuess' : function does not take 1 arguments

1>c:\documents and settings\bkhova211\my documents\visual studio 2008\projects\hilo\hilo\hilo.cpp(146) : error C2660: 'GetGuess' : function does not take 1 arguments

1>c:\documents and settings\bkhova211\my documents\visual studio 2008\projects\hilo\hilo\hilo.cpp(194) : error C2059: syntax error : 'while'

1>c:\documents and settings\bkhova211\my documents\visual studio 2008\projects\hilo\hilo\hilo.cpp(195) : error C2143: syntax error : missing ';' before '{'

1>c:\documents and settings\bkhova211\my documents\visual studio 2008\projects\hilo\hilo\hilo.cpp(195) : error C2447: '{' : missing function header (old-style formal list?)

1>c:\documents and settings\bkhova211\my documents\visual studio 2008\projects\hilo\hilo\hilo.cpp(207) : fatal error C1004: unexpected end-of-file found

1>Build log was saved at "file://c:\Documents and Settings\Bkhova211\My Documents\Visual Studio 2008\Projects\hilo\hilo\Debug\BuildLog.htm"

1>hilo - 22 error(s), 1 warning(s)

Share this post


Link to post
Share on other sites

First of all, I don't believe the following can be included in the main function. As in you cannot have function declarations in the main function. They need to be declared outside the main function and then called from the main function.

GenerateRandomNumber();
{
int random;
srand(static_cast<unsigned>(time(NULL)));
random = rand() % 100 + 1;

GetBet(int money, int& bet)
}

 

This line needs a semicolon at the end: winnings = GetBet/noOfGuesses

There are more lines than this, but I'm not going to tell you all of them.

 

When calling functions, don't include the type: Example: GetBet(int money, int& bet);

 

 

Make sure all parentheses and brackets are closed, and make the appropriate lines have semicolons.

 

Hopefully that will get you started.

Share this post


Link to post
Share on other sites

Thanks for the input i changed some things around and i still cant figure out these errors

 

/* ========================================================================== */
/* HEADER FILES */

 #include <iostream>
 #include <ctime>
 #include <cstdlib>
 #include <cmath>
 using namespace std;

// Prototypes
 void Printheading(int money);
 void PrintPayout();
 void GetBet(int money, int& bet);
 int GetGuess(void);
 int CalcNewMoney(int money, int bet, int guesses);
 int PlayAgain(void);
 int PlayGame(int money);
 int Start_Balance = 1000;
 int noOfGuesses = 0;
 int guess;
 int check;
 int random;
 int GenerateRandomNumber();
 double bank, winnings, total;
 int money = 1000,
		oldmoney = money;

/* ========================================================================== */
/* MAIN FUNCTION */
int main()
{
srand(static_cast<unsigned>(time(NULL)));
{
int random;
srand(time(NULL));
random = rand() % 100 + 1;

}

PrintPayout();
{
 cout << "If you guess correctly within the first 6 guesses, you will" << endl;
 cout << "win the amount of money you bet divided by the amount of guesses"
   << endl;
 cout << "If you don't guess correctly within the first 6 guesses you" << endl;
 cout << "lose the money that you bet" << endl;
}

GetGuess();
{
	 if (guess > random)
			 {
				check = 1;
			 }

	 else if (guess < random)
			 {
				check = -1;
			 }
	 else
			 {
				check = 0;
			 }

return();
}

int PlayGame();
{
cout << "-----------------------------------------------" << endl;
cout << "Welcome to the High-Low betting game." << endl;
cout << "You have $" << Start_Balance << "to begin the game" << endl;
cout << "Valid guesses are between the numbers 1 and 100" <<endl;
cout << "-----------------------------------------------";

cout << "Would you like to play (y / n)" << endl;

cin >> Play;
		if (Play=='y')
		{
		  winnings = GetBet/noOfGuesses;
		  cout << "Great! Your payout will be as follows:" << endl << endl;
		  PrintPayout();

		  cout << "How money would you like to bet?" << endl;
		  GetBet();

  while ((noOfGuesses < 7 ))
  {
	 cout << "Now guess a number between 1 and 100" << endl;
			 cin >> guess;
			 noOfGuesses++;
			 GetGuess();
		 if (guess == 0)
		 {
		 CalcNewMoney();
	 cout << "Correct, you win " << winnings << ", your bank is now " 
		  << CalcNewMoney << endl; 
	 cout << "Do You Wanna Play Again?(Y/N)";
	 cin >> play;
	 break;
		 }
		 else if (guess == -1)
		 {
		 cout << "Sorry too low try higher" << endl;
		 }
		 else if (guess == 1)
		 {
		 cout << "Sorry too high try lower" << endl;
		 }
  }
		}
}
return 0;
}

 

These are the errors:

>c:\documents and settings\bkhova211\my documents\visual studio 2008\projects\hilo\hilo\hilo.cpp(70) : warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data

1>c:\documents and settings\bkhova211\my documents\visual studio 2008\projects\hilo\hilo\hilo.cpp(100) : error C2059: syntax error : ')'

1>c:\documents and settings\bkhova211\my documents\visual studio 2008\projects\hilo\hilo\hilo.cpp(113) : error C2065: 'Play' : undeclared identifier

1>c:\documents and settings\bkhova211\my documents\visual studio 2008\projects\hilo\hilo\hilo.cpp(114) : error C2065: 'Play' : undeclared identifier

1>c:\documents and settings\bkhova211\my documents\visual studio 2008\projects\hilo\hilo\hilo.cpp(116) : error C2296: '/' : illegal, left operand has type 'void (__cdecl *)(int,int &)'

1>c:\documents and settings\bkhova211\my documents\visual studio 2008\projects\hilo\hilo\hilo.cpp(121) : error C2660: 'GetBet' : function does not take 0 arguments

1>c:\documents and settings\bkhova211\my documents\visual studio 2008\projects\hilo\hilo\hilo.cpp(131) : error C2660: 'CalcNewMoney' : function does not take 0 arguments

1>c:\documents and settings\bkhova211\my documents\visual studio 2008\projects\hilo\hilo\hilo.cpp(135) : error C2065: 'play' : undeclared identifier

1>Build log was saved at "file://c:\Documents and Settings\Bkhova211\My Documents\Visual Studio 2008\Projects\hilo\hilo\Debug\BuildLog.htm"

1>hilo - 7 error(s), 1 warning(s)

Share this post


Link to post
Share on other sites

The remaining errors are pretty simple, just double click on them and VS2008 will bring you to the right line.

 

return(); doesn't take parenthesis'

Play is undeclared..

GetBet/CalcNewMoney methods require arguments

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...