Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Проверить количество выбрасываний игральных костей при
- разных количествах бросков, задаваемых пользователем.
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- int main(int argc, char const *argv[])
- {
- int count, throw, cheat, cheater = 0, answer,
- dice1 = 0,
- dice2 = 0,
- dice3 = 0,
- dice4 = 0,
- dice5 = 0,
- dice6 = 0;
- printf("Введите количество бросков: \n");
- scanf("%d", &count);
- srand(time(NULL));
- count *= 2;
- if (rand() % 2 == 0)
- {
- cheat = rand() % 6 + 1;
- cheater = 1;
- }
- while(count > 0)
- {
- throw = rand() % 6 + 1;
- if (cheater == 1 && rand() % 8 == 0)
- {
- throw = cheat;
- }
- switch(throw)
- {
- case 1 : dice1++; break;
- case 2 : dice2++; break;
- case 3 : dice3++; break;
- case 4 : dice4++; break;
- case 5 : dice5++; break;
- case 6 : dice6++; break;
- }
- count--;
- }
- printf("Грань с 1 выпала: %d\n", dice1);
- printf("Грань с 2 выпала: %d\n", dice2);
- printf("Грань с 3 выпала: %d\n", dice3);
- printf("Грань с 4 выпала: %d\n", dice4);
- printf("Грань с 5 выпала: %d\n", dice5);
- printf("Грань с 6 выпала: %d\n", dice6);
- printf("Жульничал?(0 - нет, 1 - да)\n");
- scanf("%d", &answer);
- if (answer == cheater)
- {
- printf("Вы угадали!\n");
- }
- else
- {
- printf("Вы не угадали!\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement