Home » Series of Games Functions Programming Code Worksheet

Series of Games Functions Programming Code Worksheet

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, GamePlayYour Name Header Here*//*Headers/Libraries*/#include using namespace std;/*Function Declarations HERE… printRules’ declaration is included already*/void printRules();int main(){ return 0;}/*Function definition for COLLECTPAIRSthis 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 GUESSNUMBERthis 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 HIGHLOWthis 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 VIEWSTATSthis function takes in the number of wins, and losses that the user had while playing their gamesthis 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 PRINTRULESthis function prints the rules of all of the games available to the user in this programthat is all this function is responsible for. DO NOT CHANGE this function.*/void printRules(){ cout << "\nRULES:\n\nGuess the Number Game:\nYou'll only get 6 tries to guess a number between 1 and 100!\nGuess Wisely!\n\n"; cout << "High/Low Game:\nMake it through 5 rounds of guessing whether the next random number\n"; cout << "between 1 and 1,000 is higher or lower than the previous, and you win!\n\n"; cout << "Collect the Pairs Game:\nRoll two dice 100 times. If in the 100 times you roll a pair\n"; cout << "of each type (1's, 2's, 3's, 4's, 5's, 6's) at least once, then YOU WIN!\n\n"; 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 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.

Required Functions:

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().

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

    Sample Run 2 (user input underlined)

    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!

    Sample Run 3 (user input underlined)

    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!

    Sample Run 4 (user input underlined)

    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!

    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.
    Place your order
    (550 words)

    Approximate price: $22

    Calculate the price of your order

    550 words
    We'll send you the first draft for approval by September 11, 2018 at 10:52 AM
    Total price:
    $26
    The price is based on these factors:
    Academic level
    Number of pages
    Urgency
    Basic features
    • Free title page and bibliography
    • Unlimited revisions
    • Plagiarism-free guarantee
    • Money-back guarantee
    • 24/7 support
    On-demand options
    • Writer’s samples
    • Part-by-part delivery
    • Overnight delivery
    • Copies of used sources
    • Expert Proofreading
    Paper format
    • 275 words per page
    • 12 pt Arial/Times New Roman
    • Double line spacing
    • Any citation style (APA, MLA, Chicago/Turabian, Harvard)

    Our guarantees

    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.

    Money-back guarantee

    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 more

    Zero-plagiarism guarantee

    Each 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 more

    Free-revision policy

    Thanks 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 more

    Privacy policy

    Your 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 more

    Fair-cooperation guarantee

    By 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

    Order your essay today and save 30% with the discount code ESSAYHELP