Categories

dice game

#include
#include
#include

void main()
{
/*variables*/
int mydice1 ,mydice2 ,yourdice1 ,yourdice2,myresult,yourresult ;
/*seed the random number generator*/
srand((unsigned)time(NULL));
printf(“Lets play a game.n”);
printf(“The highest score of the two dice winsn”);
/*get a random number from 1 to 6*/
mydice1 = rand() % 6 + 1;
printf(“My first throw is %in”,mydice1);
/*get a random number from 1 to 6*/
mydice2 = rand() % 6 + 1;
printf(“My second throw is %in”,mydice2);
printf(“Your turn now.n”);
/*get a random number from 1 to 6*/
yourdice1 = rand() % 6 + 1;
printf(“Your first throw is %in”,yourdice1);
/*get a random number from 1 to 6*/
yourdice2 = rand() % 6 + 1;
printf(“Your second throw is %in”,yourdice2);
/*calculate the total of the two throws*/
myresult = mydice1 + mydice2;
yourresult = yourdice1 + yourdice2;
/*display the result*/
printf(“I scored %i , you scored %in”,myresult,yourresult);
if (myresult > yourresult)
printf(“I win , better luck next time.n”);
else if(myresult < yourresult)
printf(“You win , you were lucky that time.n”);
else
printf(“Its a tie.n”);

printf(“n”);
}

No related posts.

Related posts brought to you by Yet Another Related Posts Plugin.

You must be logged in to post a comment.