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

Topics: UNIX and C Programming Program Specification: Please write a C program t

ID: 3698071 • Letter: T

Question

Topics: UNIX and C Programming

Program Specification:

Please write a C program to to satisfy the requirements of Program 06 – that is re-write your MATLAB script as a C program.

program 06 is in the bottom of this text under the instructions for program 10.

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() % 6) + 1 to generate the die values

Your .c file will be many lines long

.............................................................................................................................................

Program6:

Programming Assignment #6 Due Monday, March 28th

Topics: Writing a “classic” Program in MATLAB

Game Specification:

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

There is a single player, with four six sided die.

The sides of each die are labeled with the numbers from 1 to 6, 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 four dice – you may use randi()

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 Quad is when all the dice have the same number on their top faces. If the player has any Quad then they win the round.

ii.A Triple is when exactly three of the dice have the same number on their top faces. If the player has any Triple then they win the round.

iii.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.

iv.A Two-Pair is when exactly two dice have the number on their top faces, exactly two dice have the number on their top faces, and is not equal to . If the player has any Two-Pair then they win the round.

v.A Pair is when (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.

vi.A Junker is then anything that is not listed above.   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 MATLAB Script .m file

Write the necessary MATLAB commands to meet the game specification given above

Make sure to test your “program” when it is done

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

Notes(s):

You will need to use the

<var> = randi( [1, 6], 1 );

to assign <var> a random die roll value.

Your Script will be many lines long

Sample Run(s):

     Welcome to Computer Dice

-------------------------------------

You will first roll your dice

Next the outcome of your roll will

be determined:

any Quad and you Win

any Triple and you Win

any Straight and you Win

any Two-Pair and you Win

any Pair and you just roll again

anything else and you Lose

-------------------------------------

Player

----------

1 4 5 6

Junker - Sorry, you lose!

Do you wish to play again [y, n] : 6

Do you wish to play again [y, n] : sure

Do you wish to play again [y, n] : y

Player

----------

1 2 5 5

Pair - Its a push!

Do you wish to play again [y, n] : y

Player

----------

3 3 4 5

Pair - Its a push!

Do you wish to play again [y, n] : y

Player

----------

1 3 6 6

Pair - Its a push!

Do you wish to play again [y, n] : y

Player

----------

3 3 3 4

Trip - Congrats, you win!

Do you wish to play again [y, n] : y

Player

----------

2 5 6 6

Pair - Its a push!

Do you wish to play again [y, n] : y

Player

----------

2 2 2 3

Trip - Congrats, you win!

Do you wish to play again [y, n] : y

Player

----------

3 3 3 6

Trip - Congrats, you win!

Do you wish to play again [y, n] : y

Player

----------

1 3 3 6

Pair - Its a push!

Do you wish to play again [y, n] : y

Player

----------

1 2 4 5

Junker - Sorry, you lose!

Do you wish to play again [y, n] : y

Player

----------

1 2 4 5

Junker - Sorry, you lose!

Do you wish to play again [y, n] : y

Player

----------

1 4 4 6

Pair - Its a push!

Do you wish to play again [y, n] : y

Player

----------

1 2 3 4

Straight - Congrats, you win!

Do you wish to play again [y, n] : y

Player

----------

1 3 3 5

Pair - Its a push!

Do you wish to play again [y, n] : y

Player

----------

2 3 4 5

Straight - Congrats, you win!

Do you wish to play again [y, n] : y

Player

----------

2 2 2 6

Trip - Congrats, you win!

Do you wish to play again [y, n] : y

Player

----------

3 4 4 4

Trip - Congrats, you win!

Do you wish to play again [y, n] : y

Player

----------

1 2 4 5

Junker - Sorry, you lose!

Do you wish to play again [y, n] : y

Player

----------

3 3 5 5

Two-Pair - Congrats, you win!

Do you wish to play again [y, n] : n

Computer Dice Results

---------------------

You played 19 rounds

Rounds won :8

Rounds lost    :4

---------------------

Explanation / Answer

#include<stdio.h>

#include<conio.h>

int Two_pair(int,int,int,int);

int pair(int,int,int,int);

void main()

{

int die1,die2,die3,die4,rounds=0,win=0,lose=0;

printf("roll your dies");

printf("any Quad and you Win");

printf("any Triple and you Win");

printf("any Straight and you Win");

printf("any Two-Pair and you Win");

printf("any Pair and you just roll again");

printf("anything else and you Lose");

do{

   

s:     die1=rand();

      die2=rand();

      die3=rand();

      die4=rand();

round++;

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

     {

win++;

       printf("quad -you won");

      printf("do you wish to play again");

}

else if(die1==die2 && die2==die3){

win++;

printf("trip - you won");

printf("do you wish to play again");

}

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

{

   win++;

printf("trip- you win");

printf("do you wish to play again");

}

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

win++;

printf("trip- you win"):

printf("do you wish to play again");

}

else if(die1=die2-1 && die3=die2+1 &&die4=die3+1){

win++;

printf("straight - you win");

printf("do you wish to play again");

}

else if(Two_pair(die1,die2,die3,die4)){

win++;

printf("two pair- you win");

printf("do you wish to play again");

}

else if(pair(die1,die2,die3,die4)){

printf("pair - it's a push");

goto s;

}

else{

lose++;

printf("junker- you lose");

printf("do you wish to play again");

}

}while(getchar='y');

printf("total number of rounds %d",rounds);

printf("no of wins:%d",win);

printf("no.of.lose : %d",lose);

getch();

}

int Two_pair(int a,int b,int c,int d){

if(a==b && c==d)

   return 1;

else if(a==c &&b==d)

return 1;

else if(a==d && b==c)

    return 1;

else

return 0;

}

int pair(int a,int b,int c,int d){

if(a==b || a==c ||a==d)

return 1;

if(b==c || b==d)

return 1;

if(c==d)

   return 1;

return 0;

}