Advertisement
fatman01923

Dice Roll RandomGame (TheNewBoston Task Given on video 38)

May 20th, 2016
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.97 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #include <string.h>
  5. #include <time.h>
  6.  
  7. //This code is unsophisticated!
  8. int main(){
  9.     int i;
  10.     int diceRoll1;
  11.     int diceRoll2;
  12.     int diceRoll3;
  13.     int sum1;
  14.     int sum2;
  15.     char bet;
  16.    
  17.     srand(time(NULL));
  18.    
  19.     for (i=0; i<1;i++){
  20.     diceRoll1 = rand()%6+1;
  21.     diceRoll2 = rand()%6+1;
  22.     diceRoll3 = rand()%6+1;
  23.     sum1 = diceRoll1+diceRoll2+diceRoll3;
  24.     printf("%d is the sum of the 1st roll. \n", sum1);
  25.     }
  26.     do{
  27.         for (i=0; i<1;i++){
  28.         printf("Do you think the next sum will be higher or lower?(y/n) \n", bet);
  29.         scanf(" %c", &bet);
  30.         diceRoll1 = rand()%6+1;
  31.         diceRoll2 = rand()%6+1;
  32.         diceRoll3 = rand()%6+1;
  33.         sum2 = diceRoll1+diceRoll2+diceRoll3;
  34.         printf("%d is the sum of the 2nd roll. \n", sum2);
  35.         }
  36.     }while(bet != 'y' && bet != 'n');
  37.    
  38.     if(((sum1 > sum2) && (bet=='y')) || ((sum2 > sum1) && (bet=='n'))){
  39.         printf("You guessed wrong!\n");
  40.     }else{
  41.         printf("You guessed right!\n");
  42.     }
  43.      
  44.    
  45.    
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement