Roll a die | Sololearn: Learn to code for FREE!

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

9/26/2018 4:47:19 AM

AK Evans

2 Answers

New Answer

+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; }

+1

nAutAxH AhmAd thx!!! it works!!!