Objective This 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...


Objective


This 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.


Program Description


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 .cpp file:


/*Your Name Header Here*/  /*Headers/Libraries*/ #include    using namespace std;  /*Function Declarations*/ void printRules();  int main() {     //code :-)          return 0; }  /*Function definition for COLLECTPAIRS this function is invoked whenever the user wants to play Collect Pairs. this function returns true/false depending on if the user wins the game or not*/      /*Function definition for GUESSNUMBER this function is invoked whenever the user wants to play Guess Number. this function returns true/false depending on if the user wins the game or not*/      /*Function definition for HIGHLOW this function is invoked whenever the user wants to play high low. this function returns true/false depending on if the user wins the game or not*/      /*Function definition for VIEWSTATS this function takes in the number of wins, and losses that the user had while playing their games this function then prints the win and loss stats neatly to the screen, and returns no value*/      /*Function definition for MENU  this function should print the menu for the user and ask/obtain their menu choice. this function will return the user's menu choice after verifying it's a valid choice on the menu.*/       /*Function definition for PRINTRULES this function prints the rules of all of the games available to the user in this program that is all this function is responsible for. DO NOT CHANGE this function.*/ void printRules() {     cout

I've provided you all with this starter code to help facilitate laying out/starting your program. Please use it to begin.
In this starter file, I've also provided you with the function declaration and definition for theprintRulesfunction.
You'll just need to call it when appropriate. Add code to this file to complete your homework 6.


In main():



  • Seed your random number generator

  • Enter 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 yourguessNumberfunction to play the Guess the Number game.

    • MENU OPTION 2: Call yourhighLowfunction to play the High Low game

    • MENU OPTION 3: Call yourcollectPairsfunction to play the Collect Pairs game

    • MENU OPTION 4: Call yourviewStatisticsfunction, passing in your total number of wins and losses.

    • MENU OPTION 5: Reset wins and losses back to 0.

    • MENU OPTION 6: Calls theprintRulesfunction 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.




Required Functions:



  • 1. Write a function calledmenu: This function should not take in any parameters. It should present the user with the following menu:
    GAME MENU: -------------------------- 1: PLAY Guess the Number 2: PLAY High Low 3: PLAY Collect Pairs 4: VIEW Statistics 5: RESET Statistics 6: RULES 0: 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.




  • 2. Write a function calledguessNumber.
    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().


  • 3. Write a function calledhighLow. 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.


  • 4. Write a function calledcollectPairs. 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().


  • 5. Write a function calledviewStatsthat takes in two integer parameters representing the total number of wins and losses that the user has. This function should print the total number of wins, losses, and the winning % to the screen (to 1 decimal place precision). This function should NOT return a value


  • 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.



Sample Runs:



  • ABOUT THE SAMPLE RUNS BELOW: 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.



Sample Run 1 (user input underlined)


GAME MENU: -------------------------- 1: PLAY Guess the Number 2: PLAY High Low 3: PLAY Collect Pairs 4: VIEW Statistics 5: RESET Statistics 6: RULES 0: QUIT -------------------------- > 1   Guess the Number, 1 --> 100! Attempt 1/6 : 50 TOO SMALL. Attempt 2/6 : 75 TOO BIG. Attempt 3/6 : 60 TOO SMALL. Attempt 4/6 : 68 TOO BIG. Attempt 5/6 : 65 TOO BIG. Attempt 6/6 : 63 TOO BIG. Sorry, you lose. The number was 62  GAME MENU: -------------------------- 1: PLAY Guess the Number 2: PLAY High Low 3: PLAY Collect Pairs 4: VIEW Statistics 5: RESET Statistics 6: RULES 0: QUIT -------------------------- > 1   Guess the Number, 1 --> 100! Attempt 1/6 : 50 TOO SMALL. Attempt 2/6 : 75 TOO SMALL. Attempt 3/6 : 85 TOO SMALL. Attempt 4/6 : 93 You WIN!  GAME MENU: -------------------------- 1: PLAY Guess the Number 2: PLAY High Low 3: PLAY Collect Pairs 4: VIEW Statistics 5: RESET Statistics 6: RULES 0: QUIT -------------------------- > 2   High 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?: H The next number is: 627 Correct! Round 2 of 5. The number is 627         ... is the next number [H]igher or [L]ower?: L The next number is: 474 Correct! Round 3 of 5. The number is 474         ... is the next number [H]igher or [L]ower?: H The next number is: 788 Correct! Round 4 of 5. The number is 788         ... is the next number [H]igher or [L]ower?: L The next number is: 600 Correct! Round 5 of 5. The number is 600         ... is the next number [H]igher or [L]ower?: L The next number is: 42 Correct! You WIN!  GAME MENU: -------------------------- 1: PLAY Guess the Number 2: PLAY High Low 3: PLAY Collect Pairs 4: VIEW Statistics 5: RESET Statistics 6: RULES 0: QUIT -------------------------- > 4     STATISTICS: ------------------------- Wins: 2         Losses: 1 Total Win Percent:  66.7%  GAME MENU: -------------------------- 1: PLAY Guess the Number 2: PLAY High Low 3: PLAY Collect Pairs 4: VIEW Statistics 5: RESET Statistics 6: RULES 0: QUIT -------------------------- > 5 Statistics Reset!  GAME MENU: -------------------------- 1: PLAY Guess the Number 2: PLAY High Low 3: PLAY Collect Pairs 4: VIEW Statistics 5: RESET Statistics 6: RULES 0: QUIT -------------------------- > 0  STATISTICS: ------------------------- Wins: 0         Losses: 0 Total Win Percent:  0.0%  Thanks for playing!

Sample Run 2 (user input underlined)


GAME MENU: -------------------------- 1: PLAY Guess the Number 2: PLAY High Low 3: PLAY Collect Pairs 4: VIEW Statistics 5: RESET Statistics 6: RULES 0: QUIT -------------------------- > 3  Rolling a pair of dice 100 times for pairs! PAIR OF ONES found PAIR OF FIVES found PAIR OF THREES found PAIR OF TWOS found PAIR OF SIXES found PAIR OF FOURS found  You WIN!  GAME MENU: -------------------------- 1: PLAY Guess the Number 2: PLAY High Low 3: PLAY Collect Pairs 4: VIEW Statistics 5: RESET Statistics 6: RULES 0: QUIT -------------------------- > 3  Rolling a pair of dice 100 times for pairs! PAIR OF FIVES found PAIR OF SIXES found PAIR OF FOURS found PAIR OF THREES found PAIR OF ONES found  Sorry, you lose.  GAME MENU: -------------------------- 1: PLAY Guess the Number 2: PLAY High Low 3: PLAY Collect Pairs 4: VIEW Statistics 5: RESET Statistics 6: RULES 0: QUIT -------------------------- > 3  Rolling a pair of dice 100 times for pairs! PAIR OF TWOS found PAIR OF FOURS found PAIR OF SIXES found PAIR OF THREES found  Sorry, you lose.  GAME MENU: -------------------------- 1: PLAY Guess the Number 2: PLAY High Low 3: PLAY Collect Pairs 4: VIEW Statistics 5: RESET Statistics 6: RULES 0: QUIT -------------------------- > 4  STATISTICS: ------------------------- Wins: 1         Losses: 2 Total Win Percent:  33.3%  GAME MENU: -------------------------- 1: PLAY Guess the Number 2: PLAY High Low 3: PLAY Collect Pairs 4: VIEW Statistics 5: RESET Statistics 6: RULES 0: QUIT -------------------------- > 8 Enter an item on the Menu: 9 Enter an item on the Menu: 8 Enter an item on the Menu: -10 Enter an item on the Menu: 0         STATISTICS: ------------------------- Wins: 1         Losses: 2 Total Win Percent:  33.3%  Thanks for playing!

Sample Run 3 (user input underlined)


GAME MENU: -------------------------- 1: PLAY Guess the Number 2: PLAY High Low 3: PLAY Collect Pairs 4: VIEW Statistics 5: RESET Statistics 6: RULES 0: QUIT -------------------------- > 2   High 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: H The next number is: 154 Correct! Round 2 of 5. The number is 154         ... is the next number [H]igher or [L]ower?: L The next number is: 92 Correct! Round 3 of 5. The number is 92         ... is the next number [H]igher or [L]ower?: H The next number is: 152 Correct! Round 4 of 5. The number is 152         ... is the next number [H]igher or [L]ower?: H The next number is: 256 Correct! Round 5 of 5. The number is 256         ... is the next number [H]igher or [L]ower?: H The next number is: 627 Correct! You WIN!  GAME MENU: -------------------------- 1: PLAY Guess the Number 2: PLAY High Low 3: PLAY Collect Pairs 4: VIEW Statistics 5: RESET Statistics 6: RULES 0: QUIT -------------------------- > 6  RULES:  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 number between 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 pair of 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 Number 2: PLAY High Low 3: PLAY Collect Pairs 4: VIEW Statistics 5: RESET Statistics 6: RULES 0: QUIT -------------------------- > 0   STATISTICS: ------------------------- Wins: 1         Losses: 0 Total Win Percent:  100.0%  Thanks for playing!

Sample Run 4 (user input underlined)


GAME MENU: -------------------------- 1: PLAY Guess the Number 2: PLAY High Low 3: PLAY Collect Pairs 4: VIEW Statistics 5: RESET Statistics 6: RULES 0: QUIT -------------------------- > 2   High 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?: H The next number is: 911 Correct! Round 2 of 5. The number is 911         ... is the next number [H]igher or [L]ower?: L The next number is: 211 Correct! Round 3 of 5. The number is 211         ... is the next number [H]igher or [L]ower?: L The next number is: 232 Sorry, you lose.  GAME MENU: -------------------------- 1: PLAY Guess the Number 2: PLAY High Low 3: PLAY Collect Pairs 4: VIEW Statistics 5: RESET Statistics 6: RULES 0: QUIT -------------------------- > 0   STATISTICS: ------------------------- Wins: 0         Losses: 1 Total Win Percent:  0.0%  Thanks for playing!



Requirements for the program



  • The required tasksmustbe performed with thefunctionsspecified (notjust with a singlemain()routine)

    • You must have both a function declaration and definition for your functions you write besides main()

    • Note that this exercise requires the writing of functions, and a main routine that uses those functions.

    • Each function should doexactlythe task specified. NO more no less.



  • NO global variables!

Jun 13, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions ยป

Submit New Assignment

Copy and Paste Your Assignment Here