Advertisement
Guest User

Untitled

a guest
Aug 4th, 2015
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.14 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <ctype.h>
  3. #include <stdlib.h>  // rand(), srand()
  4. #include <time.h>    // time()
  5.  
  6. int main()
  7. {
  8.     int num[2],rNum=0;
  9.     char usrinput[3];
  10.     for(int j = 0; j < 2; j++)
  11.     {
  12.         if(j == 1)
  13.         {
  14.             printf("Do you think that you will get bigger total in next turn? (y/n)");
  15.             do
  16.             {
  17.                 usrinput[1] = getchar();
  18.             }
  19.             while(usrinput[1] != 'y' && usrinput[1] != 'n');
  20.             usrinput[2] = getchar();
  21.         }
  22.         num[j] = 0;
  23.         for(int i = 1; i <= 3; i++)
  24.         {
  25.             printf("Press enter to roll the dice (turn %d/3):", i);
  26.             do
  27.             {
  28.                 usrinput[0] = getchar();
  29.             }
  30.             while(usrinput[0] != '\n');
  31.             srand(time(NULL));
  32.             rNum = (rand()%6)+1;
  33.             printf("The number you got is: %d\n", rNum);
  34.             num[j] += rNum;
  35.         }
  36.         printf("\nTotal: %d\n\n", num[j]);
  37.     }
  38.  
  39.     if((usrinput[1]=='y') && (num[1] > num[0])) printf("\n\nYou were right!\n");
  40.     else if ((usrinput[1] == 'n') && (num[1] < num[0])) printf("\n\nYou were right2!\n");
  41.     else if (num[1] == num[0]) printf("\n\nYou were wrong! Totals are of the same value!\n\n");
  42.     else printf("\n\nYou were wrong!\n");
  43.  
  44.     system("pause");
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement