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

Topics: UNIX and C Programming Game Specification: Write a C program that allows

ID: 3827463 • Letter: T

Question

Topics: UNIX and C Programming

Game Specification:

Write a C program that allows a single Player (the user) to play a simple three dice game of chance against "The Odds".

There is a single player, with three eight sided dice.

The sides of each die are labeled with the numbers from 1 to 8, we will call this the value of the die.

A game is made up of rounds, a single round is played as such:

The player rolls their three dice

The dice are displayed, in some reasonable format.

A determination is made as to whether or not the player won the round, this determination is made via the following rules:

i.A Triple is when all the dice have the same number on their top faces. If the player has any Triple then they win the round.

ii.A Straight is when the numbers on the three dice faces can be arranged to form a consecutive sequence like or    If the player has any Straight then they win the round.

iii.A Pair is when any (exactly) two dice have the same number on their top faces. If the player has any Pair then they neither win nor lose the round.

iv.A Junker is then anything that is not a Triple, a Straight or a Pair.   If the player has any Junker then they lose the round.

The result of the round (with respect to the Player) is reported.

The player is asked if they wish to play another round.

Once the player indicates that they do not wish to play another round: Before exiting, the program displays a short report stating how many rounds were played, of those - how many were won and how many were lost.

Outline:

Create a text file in your UNIX account program10.c

Edit your program10.c file to contain your C source code

Save your program10.c file

Compile your program10.c file (repeating steps 2 – 4 until it compiles without error)

Run / Test the resulting a.out file

You really need to run your program a number of times to do this thoroughly

Repeat steps 2 – 5 until it runs “correctly”

Notes(s):

Make sure to include <stdio.h> and <stdlib.h>

Use (rand() % 8) + 1 to generate the die values

Your .c file will be many lines long

Explanation / Answer

// Function prototypes.
void RollDie();
int smallWin(int);
int largeWin(int);

int main()
{
   RollDie(); // Function call.

   return 0;
} // End of main.
// Function definitions.
void RollDie()
{
   int count[11] = { 0 };
   int dice1 = 0;
   int dice2 = 0;
   int dice3 = 0;
   int won = 0;
   int lost = 0;
   int dice = 0;

   srand(static_cast<unsigned int>(time(0))); //Runs algorithm involving the number of seconds.

   while (true)
   {
      

           cout << " Please enter 1 if you wish to play a round";
           cout << " You can enter -1 to end the program. ";
           cin >> bet;
           if(bet==1)
               continue;
           else
               {
                   cout << " you won" << won << "rounds" ;
                   cout << " you lost" << lost << "rounds" ;
                   break;
               }
           dice1 = 1 + rand() % 8; //Formula for rolling a dice.
           dice2 = 1 + rand() % 8; // Formula for rolling a dice.
           dice3 = 1 + rand() % 8; // Formula for rolling a dice.
           cout << " Dice one rolled " << dice1;
           cout << " Dice two rolled " << dice2;
           cout << " Dice three rolled " << dice3;

           int sum=dice1+dice2+dice3;
           if (dice1 == dice2 && dice2 == dice3 && dice3 == dice1)
           {
               cout << " won the round : Triple";
               won++;
           }
           if (dice1 == dice2 || dice2 == dice3 ||dice1==dice3)
           {
               cout << " neither won nor lose the round : Pair";
           }
           if (sum/3==dice1 || sum/3==dice2 || sum/3==dice3)
           {
              
               cout << " you won the round : Straight";
               won++;
          
           }
           else
           {
               cout << " you lost the round : Junker";
               lost++;
              
           }}
}

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