Advertisement
Guest User

Challenge2

a guest
Jun 7th, 2015
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.87 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5. #include <math.h>
  6. #include <time.h> //for the rand() seeding randomness
  7.  
  8. int main()
  9. {
  10.     srand ( time(NULL) );
  11.  
  12.     int dice1, dice2, dice3;
  13.     int dicea, diceb, dicec;
  14.     char a, h, l, s;
  15.     int sum1, sum2;
  16.  
  17.     dice1 = ( rand()%6 ) +1;
  18.     dice2 = ( rand()%6 ) +1;
  19.     dice3 = ( rand()%6 ) +1;
  20.     sum1 = dice1 + dice2 + dice3;
  21.     printf("--------------------------------\n");
  22.     printf("  First dice: %d\n", dice1);
  23.     printf("  Second dice: %d\n", dice2);
  24.     printf("  Third dice: %d\n", dice3);
  25.     printf("  The sum of the 3 dice is %d.\n", sum1);
  26.     printf("--------------------------------\n");
  27.     printf("Guess if the next sum will be higher(h), lower(l) or the same(s).\n");
  28.  
  29.     scanf(" %c", &a);
  30.  
  31.     dicea = ( rand()%6 ) +1;
  32.     diceb = ( rand()%6 ) +1;
  33.     dicec = ( rand()%6 ) +1;
  34.     sum2 = dicea + diceb + dicec;
  35.     printf("--------------------------------\n");
  36.     printf("  First dice: %d\n", dicea);
  37.     printf("  Second dice: %d\n", diceb);
  38.     printf("  Third dice: %d\n", dicec);
  39.     printf("  The second sum is %d!\n", sum2);
  40.     printf("--------------------------------\n");
  41.  
  42.     if(a == 'h' && sum2>sum1) {
  43.             printf("Congrats!\n");
  44.             }else {
  45.                 if(a == 'h' && sum2<=sum1) { printf("You suck!");
  46.                                             }
  47.             }
  48.     if(a == 'l' && sum2<sum1) {
  49.             printf("Congrats!\n");
  50.             }else {
  51.                 if(a == 'l' && sum2>=sum1) {printf("You suck!");
  52.                                             }
  53.             }
  54.     if(a == 's' && sum2 == sum1) {
  55.             printf("Congrats!\n");
  56.             }else{
  57.                 if(a == 's' && sum2 !=sum1) {printf("You suck!");
  58.                                                 }
  59.                    }
  60.     return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement