0

Roll a die

So i am trying to write a program that ask the user how many times they would like to roll a six sided die...i want it to display the number of times the die rolls of each side. for example rolled 2 on side 1, 5 on side 2, etc

26th Sep 2018, 4:47 AM
AK Evans
AK Evans - avatar
2 Réponses
+ 4
#include <stdio.h> #include <stdlib.h> #include <time.h> int main() { srand(time(NULL)); int num=0; printf("How many times you want to roll dice: "); scanf("%d",&num); printf("\nYou entered: %d\n\n",num); int ones = 0, twos = 0, threes = 0, fours = 0, fives = 0, sixes = 0; for(int i = 0; i < num; i++) { int dice=1+rand()%6; if(dice==1) ones++; else if(dice==2) twos++; else if(dice==3) threes++; else if(dice==4) fours++; else if(dice==5) fives++; else if(dice==6) sixes++; } printf("Number One on dice came %d times\n",ones); printf("Number Two on dice came %d times\n",twos); printf("Number Three on dice came %d times\n",threes); printf("Number Four on dice came %d times\n",fours); printf("Number Five on dice came %d times\n",fives); printf("Number Six on dice came %d times\n",sixes); return 0; }
26th Sep 2018, 6:00 PM
blACk sh4d0w
blACk sh4d0w - avatar
+ 1
nAutAxH AhmAd thx!!! it works!!!
26th Sep 2018, 7:49 PM
AK Evans
AK Evans - avatar