SKETCH TO ROLL 2 DICE
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(void) {
int num =0, steps =0, dice_1 =0, dice_2 =0, sum = 0, counts = 0;
float percentage;
printf("Number of throws");
scanf(" %d", &num);
while (num > steps){
dice_1= rand() % 7;
printf(" %i ", dice_1);
dice_2 = rand() % 7;
printf(" %i \n", dice_2);
sum = dice_1+dice_2;
printf(" %i \n", sum);
steps ++;
if (sum == 8){
counts ++;}
}
percentage = (float)counts/num;
printf("Percentage of 8s: %2.3f percent", percentage);


return 0;
}

Comments

Popular posts from this blog

Seismic Code

Strings

BMP180 Code + Library to SD card