Answered You can hire a professional tutor to get the answer.
This time it should use at least four user-defined functions other than the main function.
/*I am trying to rewrite the previous program assignment. This time it should use at least four user-defined functions other than the main function. I was able to do the first and second function's name but I am getting confused on third on fourth. Please help.
* The first function's name is introduction, which will print (show on the screen)
Welcome to the Letter Guessing Game
You will enter the number of games you want to play (1 - 4 games)
You have 5 chances to guess each letter
Let's begin:
--------------------------------
* The second function's name is getNumberOfGames, which asks the user about the number of games to
be played and returns the value. This function will validate the user input to make sure it is in
the desired range (1-4) inclusive, if the value is out of range the user is notified and asked again.
How many games do you want to play (1-4) 4
* The third function's name is compareTwoCharacters, which receives two parameters of type character
(e.g. the character to be guessed in that game and the character typed by the user). This functions
return 0 if the two characters are the same, returns 2 if the first parameter comes after the second
parameter, otherwise it returns -2.
* The fourth function's name is playOneGame, which receives one parameter of type character (the
character to be guessed in that game). This function returns true if the user won; otherwise will
return false. This function will handle all tasks to play one game (ask the user to enter their
guess, provide up to 5 chances to guess, provide a hint to the user, etc.). This function is going
to call the third function (i.e. compareTwoCharacters) to decide if the user has guessed the
correct answer or to provide a hint to the user.
*/
#include "pch.h"
#include <iostream>
#include <cstdlib> //Library for rand and srand
#include <ctime> //Library for time
using namespace std;
int main()
{
//Variable Declarations
const int NUMBER_OF_GUESSES = 5;
char arr[] = { 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','k','p','q','r','s','t','u','v','w','x','y','z' };
int randomLetter, choice, count = 1;
char guess, letter;
/*Makes use of the computer's internal clock to prevent the sequence repetition between
program runs.*/
srand(static_cast<unsigned int>(time(0))); /*I originally put srand(time(NULL)). The program was
able to run for a few times until this warning C4244: 'argument' : conversion from 'time_t' to
'unsigned int', possible loss of data shows. Then I have to copy paste the whole program into
a new file again. I searched online and I hope this solved the problem. */
//Executable Statements
cout << "Welcome to the Letter Guessing Gamen";
cout << "You will enter the number of games you want to play (1-4 games)n";
cout << "You have " << NUMBER_OF_GUESSES << " chances to guess each lettern";
cout << "Let's begin:n";
cout << endl;
cout << "--------------------------------" << endl;
cout << "How many games do you want to play (1-4) ";
cin >> choice;
cout << endl;
while (count <= choice) {
randomLetter = rand() % 26;
letter = arr[randomLetter];
int num = 0;
cout << "************************************n";
cout << "Let's play game " << count << endl;
do {
cout << "Enter a guess: ";
cin >> guess;
cout << endl;
if (guess < letter) {
cout << "the letter your are trying to guess comes after " << guess << endl;
}
else if (guess > letter) {
cout << "the letter your are trying to guess comes before " << guess << endl;
}
else {
cout << "You guessed it!!!n";
cout << endl;
break;
}
num = num + 1;
if (num == NUMBER_OF_GUESSES && guess != letter) {
cout << "You did not guess the letter. It was " << letter << "n";
cout << endl;
}
} while (num < NUMBER_OF_GUESSES);
count = count + 1;
}
//Return Statement
system("PAUSE");
return 0;
}