Advertisement
zicaentu

dice3

Apr 7th, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.54 KB | None | 0 0
  1. /*
  2.  
  3.  
  4.  
  5. Проверить количество выбрасываний игральных костей при
  6. разных количествах бросков, задаваемых пользователем.
  7. */
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <time.h>
  11.  
  12. int main(int argc, char const *argv[])
  13. {
  14.     int count, throw, cheat, cheater = 0, answer,
  15.         dice1 = 0,
  16.         dice2 = 0,
  17.         dice3 = 0,
  18.         dice4 = 0,
  19.         dice5 = 0,
  20.         dice6 = 0;
  21.  
  22.     printf("Введите количество бросков: \n");
  23.     scanf("%d", &count);
  24.  
  25.     srand(time(NULL));
  26.  
  27.     count *= 2;
  28.  
  29.     if (rand() % 2 == 0)
  30.     {
  31.         cheat = rand() % 6 + 1;
  32.         cheater = 1;   
  33.     }
  34.    
  35.  
  36.     while(count > 0)
  37.     {
  38.         throw = rand() % 6 + 1;
  39.  
  40.         if (cheater == 1 && rand() % 8 == 0)
  41.         {
  42.             throw = cheat;
  43.         }
  44.  
  45.         switch(throw)
  46.         {
  47.             case 1 : dice1++; break;
  48.             case 2 : dice2++; break;
  49.             case 3 : dice3++; break;
  50.             case 4 : dice4++; break;
  51.             case 5 : dice5++; break;
  52.             case 6 : dice6++; break;
  53.         }
  54.  
  55.         count--;
  56.     }
  57.  
  58.     printf("Грань с 1 выпала: %d\n", dice1);
  59.     printf("Грань с 2 выпала: %d\n", dice2);
  60.     printf("Грань с 3 выпала: %d\n", dice3);
  61.     printf("Грань с 4 выпала: %d\n", dice4);
  62.     printf("Грань с 5 выпала: %d\n", dice5);
  63.     printf("Грань с 6 выпала: %d\n", dice6);
  64.  
  65.     printf("Жульничал?(0 - нет, 1 - да)\n");
  66.     scanf("%d", &answer);
  67.  
  68.     if (answer == cheater)
  69.     {
  70.         printf("Вы угадали!\n");
  71.     }
  72.     else
  73.     {
  74.         printf("Вы не угадали!\n");
  75.     }
  76.  
  77.     return 0;
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement