assignment will consist of writing a couple functions and allowing the student to gain practice and understanding of random number generation, and general coding skills dealing with functions, loops, and conditionals.
This program presents the user with a menu, on which includes three games: Guess the Number, High Low, and Collect Pairs. The menu also allows the user to view statistics, reset statistics and read rules of the games.
Filename: games.cpp
Start with
THIS STARTER FILE
.
/*Assignment 4 Starter File, GamePlayYour Name Header Here*//*Headers/Libraries*/#include I’ve provided you all with a starter layout to help facilite starting your program. I’ve also provided you with the function declaration and definition for the printRules function for you. You’ll just need to call it when appropriate. Seed your random number generatorEnter a loop that: [1]prints the menu and obtains the menu entry from the user (calling your menu() function will help here). [2] Determines what the entry was based on the menu, and calls the appropriate function, and [3] repeats this process until the user quits the game by choosing 0.MENU OPTION 1: Call your guessNumber function to play the Guess the Number game.MENU OPTION 2: Call your highLow function to play the High Low gameMENU OPTION 3: Call your collectPairs function to play the Collect Pairs game MENU OPTION 4: Call your viewStatistics function, passing in your total number of wins and losses.MENU OPTION 5: Reset wins and losses back to 0.MENU OPTION 6: Calls the printRules function that’s already included in your program.MENU OPTION 0: Exits. Upon exiting, print the statistics one final time to the screen.Notice, the gameplay of each game happens in the appropriate functions for those games. The stats function takes care of all the statistics printing. main() is really only responsible for setting up the menu loop that determines which functions to call. Write a function called menu: This function should not take in any parameters. It should present the user with the following menu:GAME MENU:————————–1: PLAY Guess the Number2: PLAY High Low3: PLAY Collect Pairs4: VIEW Statistics5: RESET Statistics6: RULES0: QUIT————————–>The user can select any of the options. If they select a number besides 1,2,3,4,5,6,or 0 print an error message and force them to re-enter until they enter a valid value (You’ll need a loop to force a valid entry).When the user gives a valid menu entry, the function should return it back to main() so main() can access what this value was. Note, you do not need to account for a bad character entry here, only bad integer entries. See the sample runs below for exactly how your program should behave.Write a function called guessNumber. This function takes in no values, and returns a true or false value depending on if the user wins the game or not. The function takes care of all of the gameplay:Generate a random number between 1 and 100.The user then has 6 tries to guess the secret number. If they guess the number within 6 tries, they win, and the function returns true back to main(). If they do not guess the number within 6 tries, they lose, and the function returns false back to main().On each try, print out a message indicating whether the number was too big or too small.Write a function called highLow. This function takes in no values, and returns a true or false value depending on if the user wins the game or not.The function takes care of all of the gameplay:Generate a random number between 1 and 1000 as the starting random number.The user needs to tell us whether the NEXT random number will be Higher or Lower than the current one, denoting this by entering H for higher or L for lower. The user must enter H or L here. Do not let them proceed until they do.If the user succeeds in guessing high or low correctly 5 times in a row, they win, and the function returns true back to main().If the user gets any of their guesses wrong before 5 correct guesses, they lose.Write a function called collectPairs. This function takes in no values, and returns a true or false value depending on if the user wins the game or not.The function takes care of all of the gameplay:The goal of this game is to obtain a pair of each type: 1’s, 2’s, 3’s, 4’s, 5’s, and 6’s when a pair of dice are rolled.Simulate rolling a pair of dice 100 times.When you encounter the first (and only the first) of any pair, print out a message indicating that that pair has been found and accounted for.After the 100 rolls, if the user had encountered a pair of every kind, they win, and the function should return true back to main(). If the user did not encounter all of the pairs after their 100 rolls, they lose, and the function should return false back to main(). You must have these 5 functions (explained above) in your program, in addition to main(), to earn points for these tasks. You’re allowed to create any additional functions if you choose. ABOUT THE SAMPLE RUNS: Since this assignment involves randomness, you obviously should not get the exact same values as seen below, but you should be getting SIMILAR values/percentages. GAME MENU:————————–1: PLAY Guess the Number2: PLAY High Low3: PLAY Collect Pairs4: VIEW Statistics5: RESET Statistics6: RULES0: QUIT————————–> 1Guess the Number, 1 –> 100!Attempt 1/6 : 50TOO SMALL.Attempt 2/6 : 75TOO BIG.Attempt 3/6 : 60TOO SMALL.Attempt 4/6 : 68TOO BIG.Attempt 5/6 : 65TOO BIG.Attempt 6/6 : 63TOO BIG.Sorry, you lose. The number was 62GAME MENU:————————–1: PLAY Guess the Number2: PLAY High Low3: PLAY Collect Pairs4: VIEW Statistics5: RESET Statistics6: RULES0: QUIT————————–> 1Guess the Number, 1 –> 100!Attempt 1/6 : 50TOO SMALL.Attempt 2/6 : 75TOO SMALL.Attempt 3/6 : 85TOO SMALL.Attempt 4/6 : 93You WIN!GAME MENU:————————–1: PLAY Guess the Number2: PLAY High Low3: PLAY Collect Pairs4: VIEW Statistics5: RESET Statistics6: RULES0: QUIT————————–> 2High or Low! Stay alive for 5 rounds to win! (Numbers range from 1 to 1,000)Round 1 of 5. The number is 83 … is the next number [H]igher or [L]ower?: HThe next number is: 627Correct!Round 2 of 5. The number is 627 … is the next number [H]igher or [L]ower?: LThe next number is: 474Correct!Round 3 of 5. The number is 474 … is the next number [H]igher or [L]ower?: HThe next number is: 788Correct!Round 4 of 5. The number is 788 … is the next number [H]igher or [L]ower?: LThe next number is: 600Correct!Round 5 of 5. The number is 600 … is the next number [H]igher or [L]ower?: LThe next number is: 42Correct!You WIN!GAME MENU:————————–1: PLAY Guess the Number2: PLAY High Low3: PLAY Collect Pairs4: VIEW Statistics5: RESET Statistics6: RULES0: QUIT————————–> 4 STATISTICS:————————-Wins: 2 Losses: 1Total Win Percent: 66.7%GAME MENU:————————–1: PLAY Guess the Number2: PLAY High Low3: PLAY Collect Pairs4: VIEW Statistics5: RESET Statistics6: RULES0: QUIT————————–> 5Statistics Reset!GAME MENU:————————–1: PLAY Guess the Number2: PLAY High Low3: PLAY Collect Pairs4: VIEW Statistics5: RESET Statistics6: RULES0: QUIT————————–> 0STATISTICS:————————-Wins: 0 Losses: 0Total Win Percent: 0.0%Thanks for playing! GAME MENU:————————–1: PLAY Guess the Number2: PLAY High Low3: PLAY Collect Pairs4: VIEW Statistics5: RESET Statistics6: RULES0: QUIT————————–> 3Rolling a pair of dice 100 times for pairs!PAIR OF ONES foundPAIR OF FIVES foundPAIR OF THREES foundPAIR OF TWOS foundPAIR OF SIXES foundPAIR OF FOURS foundYou WIN!GAME MENU:————————–1: PLAY Guess the Number2: PLAY High Low3: PLAY Collect Pairs4: VIEW Statistics5: RESET Statistics6: RULES0: QUIT————————–> 3Rolling a pair of dice 100 times for pairs!PAIR OF FIVES foundPAIR OF SIXES foundPAIR OF FOURS foundPAIR OF THREES foundPAIR OF ONES foundSorry, you lose.GAME MENU:————————–1: PLAY Guess the Number2: PLAY High Low3: PLAY Collect Pairs4: VIEW Statistics5: RESET Statistics6: RULES0: QUIT————————–> 3Rolling a pair of dice 100 times for pairs!PAIR OF TWOS foundPAIR OF FOURS foundPAIR OF SIXES foundPAIR OF THREES foundSorry, you lose.GAME MENU:————————–1: PLAY Guess the Number2: PLAY High Low3: PLAY Collect Pairs4: VIEW Statistics5: RESET Statistics6: RULES0: QUIT————————–> 4STATISTICS:————————-Wins: 1 Losses: 2Total Win Percent: 33.3%GAME MENU:————————–1: PLAY Guess the Number2: PLAY High Low3: PLAY Collect Pairs4: VIEW Statistics5: RESET Statistics6: RULES0: QUIT————————–> 8Enter an item on the Menu: 9Enter an item on the Menu: 8Enter an item on the Menu: -10Enter an item on the Menu: 0 STATISTICS:————————-Wins: 1 Losses: 2Total Win Percent: 33.3%Thanks for playing! GAME MENU:————————–1: PLAY Guess the Number2: PLAY High Low3: PLAY Collect Pairs4: VIEW Statistics5: RESET Statistics6: RULES0: QUIT————————–> 2High or Low! Stay alive for 5 rounds to win! (Numbers range from 1 to 1,000)Round 1 of 5. The number is 16 … is the next number [H]igher or [L]ower?: X Enter H or L: Z Enter H or L: P Enter H or L: HThe next number is: 154Correct!Round 2 of 5. The number is 154 … is the next number [H]igher or [L]ower?: LThe next number is: 92Correct!Round 3 of 5. The number is 92 … is the next number [H]igher or [L]ower?: HThe next number is: 152Correct!Round 4 of 5. The number is 152 … is the next number [H]igher or [L]ower?: HThe next number is: 256Correct!Round 5 of 5. The number is 256 … is the next number [H]igher or [L]ower?: HThe next number is: 627Correct!You WIN!GAME MENU:————————–1: PLAY Guess the Number2: PLAY High Low3: PLAY Collect Pairs4: VIEW Statistics5: RESET Statistics6: RULES0: QUIT————————–> 6RULES:Guess the Number Game:You’ll only get 6 tries to guess a number between 1 and 100!Guess Wisely!High/Low Game:Make it through 5 rounds of guessing whether the next random numberbetween 1 and 1,000 is higher or lower than the previous, and you win!Collect the Pairs Game:Roll two dice 100 times. If in the 100 times you roll a pairof each type (1’s, 2’s, 3’s, 4’s, 5’s, 6’s) at least once, then YOU WIN!GAME MENU:————————–1: PLAY Guess the Number2: PLAY High Low3: PLAY Collect Pairs4: VIEW Statistics5: RESET Statistics6: RULES0: QUIT————————–> 0STATISTICS:————————-Wins: 1 Losses: 0Total Win Percent: 100.0%Thanks for playing! GAME MENU:————————–1: PLAY Guess the Number2: PLAY High Low3: PLAY Collect Pairs4: VIEW Statistics5: RESET Statistics6: RULES0: QUIT————————–> 2High or Low! Stay alive for 5 rounds to win! (Numbers range from 1 to 1,000)Round 1 of 5. The number is 325 … is the next number [H]igher or [L]ower?: HThe next number is: 911Correct!Round 2 of 5. The number is 911 … is the next number [H]igher or [L]ower?: LThe next number is: 211Correct!Round 3 of 5. The number is 211 … is the next number [H]igher or [L]ower?: LThe next number is: 232Sorry, you lose.GAME MENU:————————–1: PLAY Guess the Number2: PLAY High Low3: PLAY Collect Pairs4: VIEW Statistics5: RESET Statistics6: RULES0: QUIT————————–> 0STATISTICS:————————-Wins: 0 Losses: 1Total Win Percent: 0.0%Thanks for playing!In main():
Required Functions:
Sample Run 1 (user input underlined)
Sample Run 2 (user input underlined)
Sample Run 3 (user input underlined)
Sample Run 4 (user input underlined)
Requirements for the program
Delivering a high-quality product at a reasonable price is not enough anymore.
That’s why we have developed 5 beneficial guarantees that will make your experience with our service enjoyable, easy, and safe.
You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.
Read moreEach paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.
Read moreThanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.
Read moreYour email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.
Read moreBy sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.
Read more