I have a program for clas that requires me to write a random number guessing game. I completed the game but i have to use functions in the program and I am not to familiar with this. Can some one help me? Here is the code and here are the functions that I have to use
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main ()
{
int num;
int guess;
bool done;
int noOfGuesses=0;
int ncount=0;
int sum=0;
int noofgamesplayed=0;
int avgNoOfGuesses=0
;sum+=noOfGuesses;
avgNoOfGuesses=sum/noofgamesplayed;
num = (rand() + time(0)) % 1000;
done = false;
while ((noOfGuesses < 10) && (!done))
{
cout << "Enter an integer greater"
<< " than or equal to 0 and "
<< "less than 1000: ";
cin >> guess;
cout << endl;
noOfGuesses++;
if (guess == num)
{
cout << "you guessed the correct "
<< "number." << endl;
done = true;
}
else
if (guess < num)
cout << "Your guess is lower "
<< "than the number. \n"
<< "Guess again!" << endl;
else
cout << "Your guess is higher "
<< "than the number.\n"
<< "guess again!" << endl;
cout <<"Total gueses equal " << noOfGuesses << endl;
}
return 0;
}
These are the functions
/*
PrintHeading simply prints the introductory output.
Parameters: initial amount of money received
*/
void PrintHeading(int money)
/*
GetBet prompts for and reads in a bet. The function performs all
error checking necessary to insure that a valid bet is read in
and does not return until a valid bet is entered.
Parameters:
money: the amount of money the player currently has
bet: the bet chosen by the user
*/
void GetBet(int money, int& bet);
/*
GetGuess reads in a guess. The user is not prompted for the guess in
this function. The user only gets one chance to input a guess value.
Return Value: the value of the guess if the input is valid
0 if the input guess was not valid
*/
int GetGuess(void);
/*
CalcNewMoney determines the amount of money the player has won or
lost during the last game.
Parameters:
money: the amount of money the player had going into the game
bet: the amount the player bet on the current game
guesses: the number of guesses it took the player to win.
-1 if the player did not guess correctly
Return Value: the new amount of money the player has
*/
int CalcNewMoney(int money, int bet, int guesses);
/*
PlayAgain prompts the user to play the game again and reads in a response,
using a single character to represent a yes or no reply.
Error checking is performed on that response.
Return Value: 1 if the user wants to play again
0 if the user does not want to play again.
*/
int PlayAgain(void);
/*
PlayGame plays a single game, performing all the necessary calculations,
input, and output.
Parameters:
money: the amount of money the player has at the start of the game.
Return Value: how much the player has after the game.
*/
int PlayGame(int money);
/*
Generates a random number between 1 and MAX_RANDOM_NUM, inclusive.
Return Value: the generated number
*/
int GenerateRandomNumber(void)
{ /* GenerateRandomNumber */
/* calculate and return a number in the required range */
return(rand() * MAX_RANDOM_NUM / RAND_MAX + 1);
} /* GenerateRandomNumber */
srand((unsigned)time(NULL));