There is a training task for throwing dice (throwing 6,000 times and displaying a “table”) in principle is elementary. I understand how everything works, but the answer does not work. Here is the code:
#include <stdio.h> #include <stdlib.h> main() { int face, roll, frequency1 = 0, frequency2 = 0, frequency3 = 0, frequency4 = 0, frequency5 = 0, frequency6 = 0; for (roll = 1; roll <= 6000; roll++) // прокручивание 6000 раз face = 1 + rand() % 6; // Добавление смещения и использование функции rand cо сдвигом масштабирования на 6 switch (face) { case 1: ++frequency1; // добавление в переменную 1 break; // конец цикла case 2: ++frequency2; break; case 3: ++frequency3; break; case 4: ++frequency4; break; case 5: ++frequency5; break; case 6: ++frequency6; break; } printf("%s%13s\n", "Face", "Frequency"); printf("1%13d\n", frequency1); printf("1%13d\n", frequency2); printf("1%13d\n", frequency3); printf("1%13d\n", frequency4); printf("1%13d\n", frequency5); printf("1%13d\n", frequency6); return 0; }
I get on exit:
Face Frequency 1 0 1 0 1 0 1 0 1 1 1 0
Can you point out my mistake?