Hey everybody. I'm writing a program that simulates rolling two dice and adds them up, eventually printing out the number of times each possibility (2 - 12) was rolled. The number of times the two dice are rolled is specified by the user. The code I've got so far compiles, but the output is way off. Can anybody give me some clues as to where I might have gone wrong?
Here's my code:
#include <stdio.h>
#include <stdlib.h>
void roll(int numtimes, int *ptr[]);
int main()
{
int numtimes = 0;
int control = 0;
int timesrolled [11];
int *arrayptr [11];
for (control = 0; control < 12; control++)
arrayptr[control] = ×rolled[control];
printf("How many times would you like to roll?");
scanf("%d", &numtimes);
roll(numtimes, arrayptr);
for (control = 0; control <= 10; control++)
printf("The number of %d's was %d\n", control+2, *arrayptr[control]);
getch();
}
void roll (int numtimes, int *ptr[])
{
int die1 = 0;
int die2 = 0;
int total = 0;
int control = 0;
for (control = 0; control < numtimes; control++)
{
die1 = rand()%7;
die2 = rand()%7;
total = die1 + die2;
*ptr[total - 2]++;
}
}