Advertisement
4C3

Dice

4C3
Oct 22nd, 2017
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.19 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <time.h>
  4. #include <stdlib.h>
  5.  
  6. int main()
  7. {
  8.     int n=3,i,total=0,total2=0;
  9.     time_t t;
  10.     char ch;
  11.     srand((unsigned)time(&t));
  12.     for(i=0;i<3;i++)    {
  13.         total+=rand()%6 +1;
  14.     }
  15.  
  16.     printf("Sum is %d\n",total);
  17.  
  18.     printf("Will the next sum of dice rolls be higher, lower, or the same? (h/l/s)\n");
  19.  
  20.     for(i=0;i<3;i++)    {
  21.         total2+=rand()%6+1;
  22.     }
  23.  
  24.     ch=getch();
  25.  
  26.     switch(ch)
  27.     {
  28.         case 'h':
  29.             if(total2>total)
  30.                 printf("Right!\n");
  31.  
  32.             else if(total2<total)
  33.                 printf("Wrong!\n");
  34.  
  35.                 printf("The 2nd number was : %d\n",total2);
  36.             break;
  37.         case 'l':
  38.             if(total2<total)
  39.                 printf("Right!\n");
  40.  
  41.             else
  42.                 printf("Wrong!\n");
  43.  
  44.                 printf("The 2nd number was : %d\n",total2);
  45.                 break;
  46.         case 's':
  47.             if(total2==total)
  48.                 printf("Right!\n");
  49.  
  50.             else
  51.                 printf("Wrong!\n");
  52.  
  53.                 printf("The 2nd number was : %d\n",total2);
  54.             break;
  55.     }
  56.     return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement