c - dice roll simulator-output frequency of each roll within histogram -


I have a complete code where the user can select the number of sides of two dice, Total number of rolls , and it prints a histogram of printed values ​​. I can not understand how to create frequency for each value, next to their respective number in the histogram, whatever I have to say is all the relevant code, if not I will add more I looked through this site and found mainly the matlab code .

  Case 2: printf ("Enter the number of trials:"); Fasts (Runinput, Psychophag (runinput), staden); Sscanf (runinput, "% d", & amp; n); If (n> gt; nmax) {printf ("Your choice of% d has exceeded the maximum test value." Set value maximum% d ", n, nmax); N = nmax; Printf ("\ n Rolling Dice ..."); Tried ++; } Other {printf ("\ n rolling dice ..."); } For (i = 0; i  gt0) {if (a [i]> gt1 = 100) {printf ("X"); A [i] = a [i] -100; } And if (a [i]> gt; = 10) {printf ("x"); A [i] = a [i] -10; } Other {printf ("*"); A [i] = a [i] -1; }}} Printf ("\ n"); } ("X = 100, X = 10, * = 1 \ n"); break;  

Whatever I am trying to add is the frequency in which the histogram has each number, any help and explanation is appreciated, I only use CS239 I am still learning so thank you in advance!

EDIT: What is the array I need to use to calculate the frequency of each number? I sometimes talk to people like this, but with its more advanced programming techniques, I know how to use or accept my instructor.

Save all the results in the same array then repeat through the array At the end of the day you can add another Get the array and you can also repeat any value through this to print it.

  $ array = [1, 6, 6, 6, 8, 9, 0,]; $ Counter = []; Forex Currency ($ array $ value) {$ counter [$ value] ++; } Print_r ($ counter); Each  key  in the Seccond array ( $ counter ) has the value of the dice roll and the key frequency of  $ value . 

Edit (wrong language): OK, I wrote PHP instead of C; Sorry: (

You can try something close to the original idea, how can you view this post and then add a number as you can find duplicate numbers in the new array and voice!

I hope this helps, then I'm worried about messing up languages: P


Comments