Write a C program where “USER” and “I” are playing six sided dice. We roll alter
ID: 3761914 • Letter: W
Question
Write a C program where “USER” and “I” are playing six sided dice. We roll alternately. If one gets a six he gets one more chance to roll. Prompt the user for how many sets he wants to play. Playing dice is like generating random numbers between 1 and six,including 1 and 6. Play those many sets, and while playing store his and your scores using two different one-dimensional arrays. Remember the two arrys may contain different numbers of data, because whoever gets a six rolls one more time for the same set for the games!! Requirements: (a) USE "calander time" as the "seed" by using commands as was done earlier: time_t one; srand(time(&one));!! (b) Main calls following function first: void PLAY_DICE(int my_score[], int your_score[], int sets,int* size_i, int* size_u); my_score[] and your_score[] are the two arrays where the function stores my and your scores. size_i and size_u are two int_addresses where the size of my_score[] and your_score[] arrays are outputed by this function. (c) Main calls the following function second: void PRINT_DICE(int my_score[], int MyGames, int your_score[], int YourGames, int* my_Total, int* your_Total); This function opens the Dice_game.txt” file and knowing the contents of the two score arrays (my_score[] and your_score[]) and their sizes(MyGames, YourGames) prints the scors in the file, and also totals mine and your scores storing them in the two integer addresses my_Total, your_Total. Typical output in “Dice_game.txt” MY_SCORES 3 5 2 1 1 1 4 1 YOUR_SCORES 2 4 1 1 3 2 6 5 6 1 (d) Main then uses the arrays to print the scores, total scores, and the results on Computer Monitor, as typically shown below: SCREEN OUT_PUT Enter number of sets to be played: 8 For 8 sets of game I rolled 8 times and you rolled 10 times. MY_SCORES 3 5 2 1 1 1 4 1 YOUR_SCORES 2 4 1 1 3 2 6 5 6 1 My Total Score= 18, Your Total Score= 31 CONGRATULATIONS YOU WON!
Press any key to continue . . .
Explanation / Answer
Program code:
// diceroling.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include<iostream>
#include <time.h>
using namespace std;
int main()
{
int i,n,j=0;
int x = 0,y=0;
int a[100],b[100];
int sum=0,sum1=0;
printf("enter the number of sets you want to play:");
scanf("%d",&n);
srand(time(0));
for(i=0;i<n;i++)
{
/*loop until a specified random number is genetrated*/
x=rand()%6;
y=rand()%6;
a[i]=x+1;
b[i]=y+1;
}
//srand(time(0));
//for(i=0;i<n;i++)
//{
//
///*loop until a specified random number is genetrated*/
//
//x=rand()%6;
//b[i]=x+1;
//
//
//}
printf("user scores:");
for(i=0;i<n;i++)
{
printf("%d ",a[i]);
}
printf(" ");
printf("your scores:");
for(i=0;i<n;i++)
{
printf("%d ",b[i]);
}
for(i=0;i<n;i++)
{
sum=sum+a[i];
sum1=sum1+b[i];
}
printf(" my total score:");
printf("%d ",sum);
printf("your total score:");
printf("%d ",sum1);
if(sum>sum1)
{
printf(" Congratulations I won!");
}
else
printf(" Congratulations You won!");
system("pause");
return 0;
}
sample output:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.