Series of Games Functions Programming Code Worksheet

Description

Having Trouble Meeting Your Deadline?

Get your assignment on Series of Games Functions Programming Code Worksheet completed on time. avoid delay and – ORDER NOW


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

/*Assignment 4 Starter File, GamePlay

Your Name Header Here

*/

/*Headers/Libraries*/
#include <iostream> 

using namespace std;

/*Function Declarations HERE... printRules' declaration is included already*/
void printRules();

int main()
{
    
    
    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 << "nRULES:nnGuess the Number Game:nYou'll only get 6 tries to guess a number between 1 and 100!nGuess Wisely!nn";
    cout << "High/Low Game:nMake it through 5 rounds of guessing whether the next random numbern";
    cout << "between 1 and 1,000 is higher or lower than the previous, and you win!nn";
    cout << "Collect the Pairs Game:nRoll two dice 100 times. If in the 100 times you roll a pairn";
    cout << "of each type (1's, 2's, 3's, 4's, 5's, 6's) at least once, then YOU WIN!nn";
    return;
}

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.

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.
    1. MENU OPTION 1: Call your guessNumber function to play the Guess the Number game.
    2. MENU OPTION 2: Call your highLow function to play the High Low game
    3. MENU OPTION 3: Call your collectPairs function to play the Collect Pairs game
    4. MENU OPTION 4: Call your viewStatistics function, passing in your total number of wins and losses.
    5. MENU OPTION 5: Reset wins and losses back to 0.
    6. MENU OPTION 6: Calls the printRules function that’s already included in your program.
    7. 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 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 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 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.
      
    3. 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.
      
    4. 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().
      
      
    5. Write a function called viewStats that 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.


  • 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.
  • 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 tasks must be performed with the functions specified (not just with a single main() 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 do exactly the task specified. NO more no less.
    • NO global variables!
    • When you write source code, it should be readable and well-documented. See the style guidelines. The appropriate header should be used.
    • You may use the libraries discussed in class for random number generation (cstdlib, ctime), as well as iostream and iomanip.
    Explanation & Answer

    Our website has a team of professional writers who can help you write any of your homework. They will write your papers from scratch. We also have a team of editors just to make sure all papers are of HIGH QUALITY & PLAGIARISM FREE. To make an Order you only need to click Order Now and we will direct you to our Order Page at Litessays. Then fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.

    Fill in all the assignment paper details that are required in the order form with the standard information being the page count, deadline, academic level and type of paper. It is advisable to have this information at hand so that you can quickly fill in the necessary information needed in the form for the essay writer to be immediately assigned to your writing project. Make payment for the custom essay order to enable us to assign a suitable writer to your order. Payments are made through Paypal on a secured billing page. Finally, sit back and relax.

    Do you need an answer to this or any other questions?

    Similar Posts