Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(5 pts) Print a game menu for Yahtzee with the following options: 1. Print game

ID: 3717790 • Letter: #

Question




(5 pts) Print a game menu for Yahtzee with the following options:

            1. Print game rules

            2. Start a game of Yahtzee

            3. Exit

(2) (5 pts) Get a menu option from the user; clear the screen

(3) (10 pts) If option 1 is entered, then print the game rules stated above and repeat step (1)

     otherwise if option 2 is entered, then continue on to step (4); player 1 starts the game

     otherwise if option 3 is entered, then print a goodbye message and quit the program

     otherwise repeat step (1)

(4) (5 pts) Ask the player to hit any key to continue on to roll the five dice

(5) (5 pts) Roll the five dice and display the face

values of each die; enumerate each die with

     a number 1 - 5; add 1 to the total number of rolls for this round

(6) (10 pts) If the total number of rolls for this round is less than three,

         then ask the player (Y/N) if he/she wants to use the roll for one of the game combinations

     otherwise a combination must be selected.

            1. Sum of 1's        7. Three-of-a-kind

            2. Sum of 2's        8. Four-of-a-kind

            3. Sum of 3's        9. Full house

            4. Sum of 4's        10. Small straight

            5. Sum of 5's        11. Large straight

            6. Sum of 6's        12. Yahtzee

                        13. Chance

(7) (15 pts) If the number of rolls is three or "yes" is entered, then save the combination and it may not be selected again in the future

          (Note: The selection of the combination must be verified. If the user selects full house, but does not have one, then your

           must assign 0 points for the combination);

          continue on to step (8); clear the screen

     otherwise if "no" is entered, ask the user which dice to re-roll (1 - 5); re-roll the selected die or dice; clear the screen;

         repeat step (6)

     otherwise repeat step (6)

(8) (5 pts) Alternate players

(9) (10 pts) If each player has rolled for the round, then increment the round number

         if the round number is equal to 14, then continue on to step (10)

         otherwise repeat step (4)

     otherwise repeat step (4)

(10) (5 pts) If the total score in the upper section is greater than or equal to 63 for a player, then add 35 points to the total score

(11) (5 pts) Print the scores for both players and print the winner

(12) (5 pts) Repeat step (1)

player has chosen to score a Dox, It may hot be changed and the combination is no long points are added to the players overall score as a bonus. The lower section contains a n Score Sum of all face values on the 5 dice Sum of all face values on the 5 dice 25 30 Name Combination Three-of-a Three dice with the same face Four dice with the same face Full house One pair and a three-of-a-kind kind Four-of-a- kind Small straightA sequence of four dice A sequence of five dice Large straight Yahtzee (think five- of-a-kind) 40 50 Five dice with the same face -May be used for any sequence of dice: Sum of all face values on the 5 dice this is the catch all combination What is required for this assignment? that ou see fit I recommend that y

Explanation / Answer

main.c

#include "function.h"

int main (void)
{
   int choice = 1, die1 = 0, die2 = 0, die3 = 0, die4 = 0, die5 = 0, die_value = 0, press = 0, roll = 0, count = 0, combination = 0, menu = 0, number = 0;
   char yes = '', no = '';

   int two = 0, three = 0, four = 0, five = 0, six = 0
   srand ((unsigned int) time (NULL));


  
   while (choice)
   {
       switch (game_menu())
       {
           case RULES:
               game_rules ();
               system("PAUSE");
               break;
           case GAME:
               run_game (die1, die2, die3, die4, die5);
               break;
           case EXIT:
               printf ("Goodbye. ");
               choice = 0;
               break;
           default:
               printf ("Illegal option. ");
               break;
       }
   return 0;
   }
}

Function.h

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define RULES 1
#define GAME 2
#define EXIT 3
#define ONE 4
#define NOT_ONE 0
#define TWO 5
#define NOT_TWO 0
#define THREE 6
#define NOT_THREE 0
#define FOUR 7
#define NOT_FOUR 0
#define FIVE 8
#define NOT_FIVE 0
#define SIX 9
#define NOT_SIX 0
#define THREE_KIND 10
#define NOT_THREE_KIND 0
#define FOUR_KIND 11
#define NOT_FOUR_KIND 0
#define SMALL 12
#define NOT_SMALL 0
#define LARGE 13
#define NOT_LARGE 0
#define FULL 14
#define NOT_FULL 0
#define CHANCE 15
#define NOT_CHANCE 0
#define YAHTZEE 16
#define NOT_YAHTZEE 0

int game_menu (void);
void game_rules (void);
int roll_die (void);
int run_game (int die1, int die2, int die3, int die4, int die5);
int get_sum_one (int die1, int die2, int die3, int die4, int die5);
int get_sum_two (int die1, int die2, int die3, int die4, int die5);
int get_sum_three (int die1, int die2, int die3, int die4, int die5);
int get_sum_four (int die1, int die2, int die3, int die4, int die5);
int get_sum_five (int die1, int die2, int die3, int die4, int die5);
int get_sum_six (int die1, int die2, int die3, int die4, int die5);
int calculate_three_kind (int die1, int die2, int die3, int die4, int die5);
int get_four_of_a_kind (int die1, int die2, int die3, int die4, int die5);
int get_small_straight (int die1, int die2, int die3, int die4, int die5);
int get_large_straight (int die1, int die2, int die3, int die4, int die5);
int get_full_house (int die1, int die2, int die3, int die4, int die5);
int get_chance (int die1, int die2, int die3, int die4, int die5);
int get_yahtzee (int die1, int die2, int die3, int die4, int die5);
int choose_combination (int yahtzee, int chance, int full_house, int large_straight, int small_straight, int four_of_a_kind, int three_of_a_kind, int sum_one, int sum_two, int sum_three, int sum_four, int sum_five, int sum_six);


Function.c
#include "function.h"

int game_menu (void)
{
   int choose = 0;
   do {
       system ("cls");
       printf ("Yahtzee ");
       printf ("%d. Print Game Rules. ", RULES);
       printf ("%d. Start a game of Yahtzee. ", GAME);
       printf ("%d. Exit ", EXIT);

       scanf ("%d", &choose);
   } while ((choose < RULES) && (choose > EXIT));
   return choose;

}
void game_rules (void)
{

   printf ("The scorecard used for Yahtzee is composed of two sections. A upper section and a lower section. ");
   printf ("A total of thirteen boxes or thirteen scoring combinations are divided amongst the sections. ");
   printf ("The upper section consists of boxes that are scored by summing the value of the dice matching the faces of the box. ");
   printf ("If a player rolls four 3's, then the score placed in the 3's box is the sum of the dice which is 12. ");
   printf ("Once a player has chosen to score a box, it may not be changed and the combination is no longer in play for future rounds. ");
   printf ("If the sum of the scores in the upper section is greater than or equal to 63, then 35 more points are added ");
   printf ("to the players overall score as a bonus. The lower section contains a number of poker like combinations. ");
}

int roll_die (void)
{
   int die_value = 0;

   die_value = rand () % 6 + 1;

   return die_value;
}
int run_game (int die1, int die2, int die3, int die4, int die5)
{
   int press = 0, roll = 0, number = 0, game = 0;
   char yes = '', no = '';

   do
           {
               printf (" Press any key in order to role the dice!!");
               scanf ("%d", &press);
               die1 = roll_die (1);
               printf ("Die 1: %d ",die1);
               die2 = roll_die (2);
               printf ("Die 2: %d ",die2);
               die3 = roll_die (3);
               printf ("Die 3: %d ",die3);
               die4 = roll_die (4);
               printf ("Die 4: %d ",die4);
               die5 = roll_die (5);
               printf ("Die 5: %d ",die5);
               roll++;
           }while (press != press);
               printf ("That is roll number %d ", roll);
           while (roll < 3)
               {
                   printf ("Would you like to use this role for a game combination?(press Y for yes or N for no) ");
                   scanf (" %c %c", &yes, &no);
          
                   if ((yes == 'y')||(yes == 'Y'))
                   {
                       printf("What combination would you like to use? ");
                       printf("(Press the number of the combination you would like to use.) ");
                       printf("%d. Sum of 1's. ", ONE);
                       printf("%d. Sum of 2's. ", TWO);
                       printf("%d. Sum of 3's. ", THREE);
                       printf("%d. Sum of 4's. ", FOUR);
                       printf("%d. Sum of 5's. ", FIVE);
                       printf("%d. Sum of 6's. ", SIX);
                       printf("%d. Three of a Kind. ", THREE_KIND);
                       printf("%d. Four of a Kind. ", FOUR_KIND);
                       printf("%d. Full House. ", FULL);
                       printf("%d. Small Straight. ", SMALL);
                       printf("%d. Large Straight. ", LARGE);
                       printf("%d. Yahtzee. ", YAHTZEE);
                       printf("%d. Chance ", CHANCE);
                       scanf("%d", &number);
                      
                   }
                   else if ((no == 'n')||(no == 'N'))
                   {
                       printf("Would you like to keep any of the dice you just rolled? (press Y for yes and N for no) ");
                       scanf(" %c %c", &yes, &no);
                          
                       if ((yes == 'y')||(yes == 'Y'))
                       {
                           printf ("Please enter the die number you would like to save.");
                          

                       }
                       else
                       {
                           return 0;
                       }
                              
                   }
           }
           while (roll == 3)
           {
               printf ("What combination would you like to use?");
               printf("What combination would you like to use? ");
               printf("(Press the number of the combination you would like to use.) ");
               printf("%d. Sum of 1's. ", ONE);
               printf("%d. Sum of 2's. ", TWO);
               printf("%d. Sum of 3's. ", THREE);
               printf("%d. Sum of 4's. ", FOUR);
               printf("%d. Sum of 5's. ", FIVE);
               printf("%d. Sum of 6's. ", SIX);
               printf("%d. Three of a Kind. ", THREE_KIND);
               printf("%d. Four of a Kind. ", FOUR_KIND);
               printf("%d. Full House. ", FULL);
               printf("%d. Small Straight. ", SMALL);
               printf("%d. Large Straight. ", LARGE);
               printf("%d. Yahtzee. ", YAHTZEE);
               printf("%d. Chance ", CHANCE);
               scanf("%d", &number);
           }


}