I cannot get all the inputs to produce the correct ou

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

/*

yahtC

*/

#include <stdio.h>

#include <string.h>

#include <stdlib.h>

#include <time.h>

 

void seed(int argc, char ** argv){

srand(time(NULL)); // Initialize random seed

if (argc>1){

int i;

if (1 == sscanf(argv[1],"%d",&i)){

srand(i);

}

}

}

void instructions(){

printf("\n\n\n\n"

"\t**********************************************************************\n"

"\t* Welcome to YahtC *\n"

"\t**********************************************************************\n"

"\tYahtC is a dice game (very) loosely modeled on Yahtzee\n"

"\tBUT YahtC is not Yahtzee.\n\n"

"\tRules:\n"

"\t5 dice are rolled\n"

"\tThe user selects which dice to roll again.\n"

"\tThe user may choose to roll none or all 5 or any combination.\n"

"\tAnd then the user selects which dice to roll, yet again.\n"

"\tAfter this second reroll the turn is scored.\n\n"

"\tScoring is as follows:\n"

"\t\t*\t50 points \t5 of a kind scores 50 points.\n"

"\t\t*\t45 points \tNo pairs (all unique) scores 45 points.\n"

"\t\t*\t40 points \t4 of a kind scores 40 points.\n"

"\t\t*\t30 points \t3 of a kind scores 30 points.\n"

"\t\t*\tTotal Dice\tOtherwise score the dice total.\n\n"

"\tTo indicate nothing to reroll the user will input 0\n"

"\tThis should end the players turn.\n"

"\tOtherwise the user will indicate which dice to reroll by position\n"

"\t135 would indicate to reroll the first, third and last die.\n"

"\tThe numbers do not have to be given in order\n"

"\tThe game ends after 7 turns.\n"

"\t**********************************************************************\n\n\n");

}

 

int rolls() {

return (rand() % 6) + 1;

}

int scoreCheck(int dice[]) {

int score = 0;

for (int i = 0; i < 5; i++) {

for (int j = i + 1; j < 5; j++) {

if (dice[j] < dice[i]) {

int temp = dice[i];

dice[i] = dice[j];

dice[j] = temp;

}

}

}

 

int counts[6] = {0};



for (int i = 0; i < 5; i++) {

counts[dice[i] - 1]++;

}

 

int maxCount = 0;

int maxCountIndex = -1;

 

 

for (int i = 0; i < 6; i++) {

if (counts[i] > maxCount) {

maxCount = counts[i];

maxCountIndex = i;

}

}

 

 

if (maxCount == 5) {

score = 50;

} else if (maxCount == 1) {

score = 45;

} else if (maxCount == 4) {

score = 40;

} else if (maxCount == 3) {

score = 30;

} else {

for (int i = 0; i < 5; i++) {

score += dice[i];

}

}

 

return score;

}

 

int main(int argc, char **argv) {

seed(argc, argv);

instructions();

 

int dice[5] = {0};

int totalScore = 0;

int turns = 7;

printf("----------\n");

printf("SCORESHEET\n");

printf("----------\n");

for (int turn = 1; turn <= turns; turn++) {

printf("Turn %d: ", turn);

for (int i = 0; i < 5; i++) {

dice[i] = rolls();

}

 

int selectedDice;

scanf("%d", &selectedDice);

if (selectedDice >= 1 && selectedDice <= 5) {

dice[selectedDice - 1] = rolls();

}

 

for (int i = 0; i < 5; i++) {

}

 

scanf("%d", &selectedDice);

if (selectedDice >= 1 && selectedDice <= 5) {

dice[selectedDice - 1] = rolls();

}

int score = scoreCheck(dice);

printf("%d\n", scoreCheck(dice));

totalScore += score;

}

printf("==========\n");

printf("Total: %d\n", totalScore);



return 0;

}


In c code, this is the prompt

********************************************************************** * Welcome to YahtC * ********************************************************************** YahtC is a dice game (very) loosely modeled on Yahtzee BUT YahtC is not Yahtzee. Rules: 5 dice are rolled The user selects which dice to roll again. The user may choose to roll none or all 5 or any combination. And then the user selects which dice to roll, yet again. After this second reroll the turn is scored. Scoring is as follows: * 50 points 5 of a kind scores 50 points. * 45 points No pairs (all unique) scores 45 points. * 40 points 4 of a kind scores 40 points. * 30 points 3 of a kind scores 30 points. * Total Dice Otherwise score the dice total. To indicate nothing to reroll the user will input 0 This should end the players turn. Otherwise the user will indicate which dice to reroll by position 135 would indicate to reroll the first, third and last die. The numbers do not have to be given in order The game ends after 7 turns. ********************************************************************** First Roll = 24512 Select dice to reroll:1 second:64512 Select dice to reroll:0 score for 64512 is 45 First Roll = 25665 Select dice to reroll:1 second:55665 Select dice to reroll:34 final:55515 score for 55515 is 40 First Roll = 55224 Select dice to reroll:5 second:55221 Select dice to reroll:5 final:55222 score for 55222 is 30 First Roll = 26566 Select dice to reroll:13 second:36466 Select dice to reroll:13 final:36566 score for 36566 is 30 First Roll = 21511 Select dice to reroll:13 second:11311 Select dice to reroll:3 final:11311 score for 11311 is 40 First Roll = 51411 Select dice to reroll:13 second:61211 Select dice to reroll:13 final:61511 score for 61511 is 30 First Roll = 44154 Select dice to reroll:34 second:44434 Select dice to reroll:4 final:44464 score for 44464 is 40 ---------- SCORESHEET ---------- Turn 1: 45 Turn 2: 40 Turn 3: 30 Turn 4: 30 Turn 5: 40 Turn 6: 30 Turn 7: 40 ========== Total: 255

I cannot get all the inputs to produce the correct outputs.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 6 steps with 5 images

Blurred answer
Knowledge Booster
Fundamentals of Boolean Algebra and Digital Logics
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education