You are playing a game where you roll a die 6 times. If you roll a 5 or 6 four o
ID: 3533668 • Letter: Y
Question
You are playing a game where you roll a die 6 times. If you roll a 5 or 6 four or more times, you win 4 dollars, two or three times,you win 2 dollar, and if you roll a 5 or 6 one or less times, you win no money. Write a function called diceGame that takes in a vector representing the dice values and returns the amount of money won.
For example:
diceGame([5 1 4 6 5 5]) should return 4
Test your program for the following three cases:
diceGame([2 4 1 3 6 6])
diceGame([1 4 3 2 5 3])
Note: This function should work for any length vector.
Please Help!!!!
Explanation / Answer
#include<stdio.h>
//Function prototype
int RollScore(int , int);
main()
{
int LoopCount;
LoopCount = 0;
for(LoopCount = 0; LoopCount < 11; LoopCount ++)
{
//Declare Variables
int DieOne,DieTwo,DiceScore;
// One and Two will be hidden only Score will be output
DieOne = 0;
DieTwo = 0;
DiceScore = 0;
printf(" To win you need a score of 7 or 11.");
printf(" Press a key to Roll the Dice!");
//Trigger Random number generator and remove previous text
getch();
system("cls");
DiceScore = RollScore(DieOne , DieTwo);
//Create Condition to either show user a win/lose output
if (DiceScore == 7 || DiceScore == 11)
{
printf(" You Rolled a score of %d" , DiceScore);
printf(" Congratulation! You win!");
LoopCount = 11;
}//end if
else
{
printf(" You Rolled a score of %d" , DiceScore);
printf(" Sorry you have lost! Thanks for playing!");
printf(" %d Attempt!" , LoopCount);
}//end else
//Prevent the IDE from closing program upon termination
getch();
system("cls");
}//End For
}
//Function definition
int RollScore (int Dieone , int Dietwo)
{
return (srand() % 5) + 1 , (srand() % 5) + 1;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.