C programing check this link to understand the game . www.yahtzeeonline.org. the
ID: 3595894 • Letter: C
Question
C programing
check this link to understand the game .
www.yahtzeeonline.org.
the game is text based however.
Explanation / Answer
code for the above program:
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
void score();
int main()
{ void gamerules();
void game();
int choice;
int i=1;
do{
printf("***MENU*** 1.Print the rules 2.Start a new Game 3.Exit Enter one of the input value (1,2,3) :");
scanf("%d",&choice);
system("cls");
switch(choice)
{
case 1: gamerules();break;
case 2: game();break;
case 3: printf("Goodbye from the game ");exit(0);
}
i=choice;
}while(i!=1||i!=2);
}
void gamerules()
{
//you can write the rules on your own
}
void game()
{
int dice[5];int count=0,i;int move;int ch;int verify[13]={0};int rrl;int ch1;
printf("press any key (0-9) to roll the dice ");
scanf("%d",&move);
for(i=0;i<5;i++)
dice[i]=rand()% 6 + 1 ;
printf("face value of each dice 1-->%d 2-->%d 3-->%d 4-->%d 5-->%d ",dice[0],dice[1],dice[2],dice[3],dice[4]);
count++;
printf("select one of the combination ");
printf("1.Sum of 1's 2.Sum of 2's 3.Sum of 3's 4.Sum of 4's 5.Sum of 5's 6.Sum of 6's 7.Three of a kind 8.Four of a kind 9.Fullhouse 10.Small straight 1.Large straight 12.Yahtzee 13.Chance ");
scanf("%d",&ch1);
do
{
printf("if you want to use the roll for combination-- press 0/1 ? ");
scanf("%d",&ch);
if(ch==1)
select_combination(ch1,dice,verify);
else if(ch==0)
{
printf("which dice u want to re-roll (1-5)");
count++;
for(i=0;i<5;i++)
{
printf("want to re-roll dice %d press 0/1 ?",i+1);
scanf("%d",&rrl);
if(rrl==1)
dice[i]=rand()%6+1;
}
printf("face value of eacj dice 1-->%d 2-->%d 3-->%d 4-->%d 5-->%d ",dice[0],dice[1],dice[2],dice[3],dice[4]);
}
}while(count!=3&&ch==0);
}
void select_combination(int ch,int* dice,int* verify)
{
if(verify[ch-1]==0){
verify[ch-1]=1;score(dice,ch);
}
else
{
printf("combination used ");
score(0);
}
}
void score()
{
//as no details is told about scoring part,,,,it is left to user
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.