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

3:31 PM eecs.wsu.edu ntl Verizon I. Learner Objectives: At the conclusion of thi

ID: 3722690 • Letter: 3

Question

3:31 PM eecs.wsu.edu ntl Verizon I. Learner Objectives: At the conclusion of this programming assignment, participants should be able to: Apply repetition structures within algorithms *Construct while , for 0, or do-while loops in C 8Apply pointers, output parameters, and/or arrays in C sCompose C programs consisting of sequential, conditional, and iterative statements Eliminate redundancy within a program by applying loops and functions Create structure charts for a given problem Determine an appropriate functional decomposition or top-down design from a structure chart s Generate random numbers for use within a C program Before starting this programming assignment, participants should be able to: Analyze a basic set of requirements and apply top-down design principles for a e problem e Customize and define C functions e Apply the 3 file format: 1 header file and 2 source files e Open and close files e Read, write to, and update files Apply standard library functions: fopen 0, fclose ), fscanf ), and fprintf O e Compose decision statements if conditional statements) e Create and utilize compound conditions Summarize topics from Hanly & Koffman Chapter 4 &5 including: e What are counting, conditional, sentinel-controlled, flag-controlled, and end file controlled loops What are while O. do-while (), and for ( ) loops e What is a selection or conditional statement e What is a compound condition e What is a Boolean expression e What is a flowchart Ill. Overview & Requirements: Develop and implement an interactive two-player Yahtzee game. Yahtzee is a dice game that was invented by Milton Bradley and Edwin S. Lowe in 1956. The challenge of the game is to outduel the other player by scoring the most points. Points are obtained by rolling five 6-sided die across thirteen rounds. During each round, each player may roll the dice up to three times to make one of the possible scoring combinations. Once a combination has been achieved by the player, it may not be used again in future rounds, except for the Yahtzee combination may be used as many times as the player makes the combination. Each scoring combination has different point totals. Some of these totals are achieved through the accumulation of points across rolls and some are obtained as fixed sequences of values. The Rules of Yahtzee: The scorecard used for Yahtzee is composed of two sections. A upper section and a lower section. A total of thirteen boxes or thirteen scoring combinations are divided amongst the sections. The upper section consists of boxes that are scored by summing the value of the dice matching the faces of the box. 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. Once a player has chosen to score a bax, it may not be changed and the combination is no longer in play for future rounds. If the sum of the scores in the upper section is greater than or equal to 63, then 35 more points are added to the players overall score as a bonus. The lower section contains a number of poker like combinations. See the table provided below:

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> /* Header file for scanf ( ), printf ( ) */
#include <stdlib.h> /* Header file for system ( ) */
#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);

}

}

/*int get_sum_one (int die1, int die2, int die3, int die4, int die5)

{

int sum_one = 0;

if ((die1 == '1')||(die2 == '1')||(die3 == '1')||(die4 == '1')||(die5 == '1'))

{

sum_one = die1 + die2 + die3 + die4 + die5;

return sum_one;

}

else

{

return 0;

}

int get_sum_two (int die1, int die2, int die3, int die4, int die5)

{

int sum_two = 0;

if (die1 == '2')

{

die1 = 2;

}

else

{

return 0;

}

if (die2 == '2')

{

die2 = 2;

}

else

{

return 0;

}

if (die3 == '2')

{

die3 = 2;

}

else

{

return 0;

}

if (die4 == '2')

{

die4 = 2;

}

else

{

return 0;

}

if (die5 == '2')

{

die5 = 2;

}

else

{

return 0;

}

sum_two = die1 + die2 + die3 + die4 + die5;

return sum_two;

}

int get_sum_three (int die1, int die2, int die3, int die4, int die5)

{

int sum_three = 0;

if (die1 == '3')

{

die1 = 3;

}

else

{

return 0;

}

if (die2 == '3')

{

die2 = 3;

}

else

{

return 0;

}

if (die3 == '3')

{

die3 = 3;

}

else

{

return 0;

}

if (die4 == '3')

{

die4 = 3;

}

else

{

return 0;

}

if (die5 == '3')

{

die5 = 3;

}

else

{

return 0;

}

sum_three = die1 + die2 + die3 + die4 + die5;

return sum_three;

}

int get_sum_four (int die1, int die2, int die3, int die4, int die5)

{

int sum_four = 0;

if (die1 == '4')

{

die1 = 4;

}

else

{

return 0;

}

if (die2 == '4')

{

die2 = 4;

}

else

{

return 0;

}

if (die3 == '4')

{

die3 = 4;

}

else

{

return 0;

}

if (die4 == '4')

{

die4 = 4;

}

else

{

return 0;

}

if (die5 == '4')

{

die5 = 4;

}

else

{

return 0;

}

sum_four = die1 + die2 + die3 + die4 + die5;

return sum_four;

}

int get_sum_five (int die1, int die2, int die3, int die4, int die5)

{

int sum_five = 0;

if (die1 == '5')

{

die1 = 5;

}

else

{

return 0;

}

if (die2 == '5')

{

die2 = 5;

}

else

{

return 0;

}

if (die3 == '5')

{

die3 = 5;

}

else

{

return 0;

}

if (die4 == '5')

{

die4 = 5;

}

else

{

return 0;

}

if (die5 == '5')

{

die5 = 5;

}

else

{

return 0;

}

sum_five = die1 + die2 + die3 + die4 + die5;

return sum_five;

}

int get_sum_six (int die1, int die2, int die3, int die4, int die5)

{

int sum_six = 0;

if (die1 == '6')

{

die1 = 6;

}

else

{

return 0;

}

if (die2 == '6')

{

die2 = 6;

}

else

{

return 0;

}

if (die3 == '6')

{

die3 = 6;

}

else

{

return 0;

}

if (die4 == '6')

{

die4 = 6;

}

else

{

return 0;

}

if (die5 == '6')

{

die5 = 6;

}

else

{

return 0;

}

sum_six = die1 + die2 + die3 + die4 + die5;

return sum_six;

}*/

/*int calculate_three_kind (int die1, int die2, int die3, int die4, int die5)

{

int three_of_a_kind = 0;

if(calculate_three_kind)

{

if((die1 == die2) && (die1 == die3) || (die1 == die4) || (die1 == die5))

{

three_of_a_kind = die1 + die1 + die1;

printf ("Your score for three of a kind is: %d", &three_of_a_kind);

system("PAUSE");

return;

}

else if((die1 == die3) && (die1 == die4) || (die1 == die5))

{

three_of_a_kind = die1 + die1 + die1;

printf ("Your score for three of a kind is: %d", &three_of_a_kind);

system("PAUSE");

return;

}

else if((die1 == die4) && (die1 == die5))

{

three_of_a_kind = die1 + die1 + die1;

printf ("Your score for three of a kind is: %d", &three_of_a_kind);

system("PAUSE");

return;

}

else if((die2 == die3) && (die2 == die4) || (die2 == die5))

{

three_of_a_kind = die2 + die2 + die2;

printf ("Your score for three of a kind is: %d", &three_of_a_kind);

system("PAUSE");

return;

}

else if((die2 == die4) && (die2 == die5))

{

three_of_a_kind = die2 + die2 + die2;

printf ("Your score for three of a kind is: %d", &three_of_a_kind);

system("PAUSE");

return;

}

else if((die3 == die4) && (die3 == die5))

{

three_of_a_kind = die3 + die3 + die3;

printf ("Your score for three of a kind is: %d", &three_of_a_kind);

system("PAUSE");

return;

}

else

{

printf ("Your score for three of a kind is: %d", &three_of_a_kind);

three_of_a_kind = 0;

system("PAUSE");

return;

}

else if(calculate_three_kind != three_of_a_kind)

{

printf ("Sorry, You already saved that slot.");

system("PAUSE");

}

}

}

int get_four_of_a_kind (int die1, int die2, int die3, int die4, int die5)

{

int four_of_a_kind = 0;

if(get_four_of_a_kind)

{

if((die1 == die2) && (die1 == die3) && (die1 == die4) || (die1 == die5))

{

four_of_a_kind = die1 + die1 + die1 + die1;

printf ("Your score for four of a kind is: %d", &four_of_a_kind);

system("PAUSE");

return;

}

else if((die1 == die2) && (die1 == die4) && (die1 == die3) || (die1 == die5))

{

four_of_a_kind = die1 + die1 + die1 + die1;

printf ("Your score for four of a kind is: %d", &four_of_a_kind);

system("PAUSE");

return;

}

else if((die1 == die2) && (die1 == die5) && (die1 == die3) || (die1 == die4))

{

four_of_a_kind = die1 + die1 + die1 + die1;

printf ("Your score for four of a kind is: %d", &four_of_a_kind);

system("PAUSE");

return;

}

else if((die1 == die3) && (die1 == die4) && (die1 == die2) || (die1 == die5))

{

four_of_a_kind = die1 + die1 + die1 + die1;

printf ("Your score for four of a kind is: %d", &four_of_a_kind);

system("PAUSE");

return;

}

else if((die1 == die3) && (die1 == die5) && (die1 == die2) || (die1 == die4))

{

four_of_a_kind = die1 + die1 + die1 + die1;

printf ("Your score for four of a kind is: %d", &four_of_a_kind);

system("PAUSE");

return;

}

else if((die1 == die4) && (die1 == die5) && (die1 == die2) || (die1 == die3))

{

four_of_a_kind = die1 + die1 + die1 + die1;

printf ("Your score for four of a kind is: %d", &four_of_a_kind);

system("PAUSE");

return;

}

else if((die2 == die3) && (die2 == die4) && (die2 == die5))

{

four_of_a_kind = die2 + die2 + die2 + die2;

printf ("Your score for four of a kind is: %d", &four_of_a_kind);

system("PAUSE");

return;

}

else

{

printf ("Your score for four of a kind is: %d", &four_of_a_kind);

four_of_a_kind = 0;

system("PAUSE");

return;

}

if(get_four_of_a_kind != four_of_a_kind)

{

printf ("You have already used you four of a kind.");

system("PAUSE");

}

}

}

int get_small_straight (int die1, int die2, int die3, int die4, int die5)

{

int small_straight = 0;

if(get_small_straight)

{

if((die1 != die2) && (die1 != die3) && (die1 != die4) && (die1 != die5))

{

if((die2 != die3) && (die2 != die4) && (die2 != die5))

{

if((die3 != die4) && (die3 != die5))

{

if(die4 != die5)

{

if((die1 != '6') && (die2 != '6') && (die3 != '6') && (die4 != '6') && (die5 != '6'))

{

small_straight = die1 + die2 + die3 + die4 + die5;

printf ("Your score for small straight is: %d", &small_straight);

system("PAUSE");

return;

}

else

{

printf ("Your score for small straight is: %d", &small_straight);

small_straight = 0;

system("PAUSE");

return;

}

}

else

{

printf ("Your score for small straight is: %d", &small_straight);

small_straight = 0;

system("PAUSE");

return;

}

else

{

printf ("Your score for small straight is: %d", &small_straight);

small_straight = 0;

system("PAUSE");

return;

}

else

{

printf ("Your score for small straight is: %d", &small_straight);

small_straight = 0;

system("PAUSE");

return;

}

else

{

printf ("Your score for small straight is: %d", &small_straight);

small_straight = 0;

system("PAUSE");

return;

}

else

{

printf ("Your score for small straight is: %d", &small_straight);

small_straight = 0;

system("PAUSE");

return;

}

if(get_small_straight != small_straight)

{

printf ("You already used your small_straight");

system("PAUSE");

}

}

}

}

}

}

int get_large_straight (int die1, int die2, int die3, int die4, int die5)

{

int large_straight = 0;

if(get_large_straight)

{

if((die1 != die2) && (die1 != die3) && (die1 != die4) && (die1 != die5))

{

if((die2 != die3) && (die2 != die4) && (die2 != die5))

{

if((die3 != die4) && (die3 != die5))

{

if(die4 != die5)

{

if((die1 != '6') && (die2 != '6') && (die3 != '6') && (die4 != '6') && (die5 != '6'))

{

large_straight = die1 + die2 + die3 + die4 + die5;

printf ("Your score for large straight is: %d", &large_straight);

system("PAUSE");

return;

}

else

{

printf ("Your score for large straight is: %d", &large_straight);

large_straight = 0;

system("PAUSE");

return;

}

  

else

{

printf ("Your score for large straight is: %d", &large_straight);

large_straight = 0;

system("PAUSE");

return;

}

else

{

printf ("Your score for large straight is: %d", &large_straight);

large_straight = 0;

system("PAUSE");

return;

}

else

{

printf ("Your score for large straight is: %d", &large_straight);

large_straight = 0;

system("PAUSE");

return;

}

else

{

printf ("Your score for large straight is: %d", &large_straight);

large_straight = 0;

system("PAUSE");

return;

}

else

{

printf ("Your score for large straight is: %d", &large_straight);

large_straight = 0;

system("PAUSE");

return;

}

if(get_large_straight != large_straight)

{

printf ("You already used your Large Straight.");

system("PAUSE");

}

}

}

}

}

}

}

int get_full_house (int die1, int die2, int die3, int die4, int die5)

{

int full_house = 0;

if(get_full_house)

{

if((die1 == die2) && (die1 == die3) && (die4 == die5))

{

full_house = die1 + die2 + die3 + die4 + die5;

printf ("Your score for full house is: %d", &full_house);

system("PAUSE");

return;

}

else if((die1 == die2) && (die1 == die4) && (die3 == die5))

{

full_house = die1 + die2 + die3 + die4 + die5;

printf ("Your score for full house is: %d", &full_house);

system("PAUSE");

return;

}

else if((die1 == die2) && (die1 == die5) && (die3 == die4))

{

full_house = die1 + die2 + die3 + die4 + die5;

printf ("Your score for full house is: %d", &full_house);

system("PAUSE");

return;

}

else if((die1 == die3) && (die1 == die4) && (die2 == die5))

{

full_house = die1 + die2 + die3 + die4 + die5;

printf ("Your score for full house is: %d", &full_house);

system("PAUSE");

return;

}

else if((die1 == die3) && (die1 == die5) && (die2 == die4))

{

full_house = die1 + die2 + die3 + die4 + die5;

printf ("Your score for full house is: %d", &full_house);

system("PAUSE");

return;

}

else if((die1 == die4) && (die1 == die5) && (die2 == die3))

{

full_house = die1 + die2 + die3 + die4 + die5;

printf ("Your score for full house is: %d", &full_house);

system("PAUSE");

return;

}

else if((die2 == die3) && (die2 == die4) && (die1 == die5))

{

full_house = die1 + die2 + die3 + die4 + die5;

printf ("Your score for full house is: %d", &full_house);

system("PAUSE");

return;

}

else if((die2 == die3) && (die2 == die5) && (die1 == die4))

{

full_house = die1 + die2 + die3 + die4 + die5;

printf ("Your score for full house is: %d", &full_house);

system("PAUSE");

return;

}

else if((die2 == die4) && (die2 == die5) && (die1 == die3))

{

full_house = die1 + die2 + die3 + die4 + die5;

printf ("Your score for full house is: %d", &full_house);

system("PAUSE");

return;

}

else if((die3 == die4) && (die3 == die5) && (die1 == die2))

{

full_house = die1 + die2 + die3 + die4 + die5;

printf ("Your score for full house is: %d", &full_house);

system("PAUSE");

return;

}

else

{

printf ("Your score for full house is: %d", &full_house);

full_house = 0;

system("PAUSE");

return;

}

}

if(get_full_house != full_house)

{

printf ("You already used your Full House.");

system("PAUSE");

}

}

int get_chance (int die1, int die2, int die3, int die4, int die5)

{

int chance = 0;

if(get_chance)

{

chance = die1 + die2 + die3 + die4 + die5;

printf ("Your score for your chance is: %d", &chance);

system("PAUSE");

return;

}

else if(get_chance != chance)

{

printf ("You already used up your chance.");

system("PAUSE");

}

}

int get_yahtzee (int die1, int die2, int die3, int die4, int die5)

{

int yahtzee = 0;

if(get_yahtzee)

{

if((die1 == die2) && (die1 == die3) && (die1 == die4) && (die1 == die5))

{

yahtzee = 50;

printf ("You got a Yahtzee worth 50 points.");

system("PAUSE");

return;

}

else

{

printf ("Your new score for Yahtzee are: %d", &yahtzee);

system("PAUSE");

return;

}

}

if(get_yahtzee != yahtzee)

{

printf ("You already used up your yahtzee");

system("PAUSE");

}

}

*/

//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)

//{

//if

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote