Advertisement
thenewboston

Forum reply about two lines error

Aug 24th, 2014
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.88 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <ctype.h>
  4. #include <string.h>
  5. #include <math.h>
  6.  
  7. int main()
  8. {
  9.     int i;
  10.     int dice1;
  11.     int dice2;
  12.     int dice3;
  13.     int sum1;
  14.     int sum2;
  15.     char input;
  16.     int input1; // this should be a int, not a char
  17.  
  18.     srand(time(NULL));
  19.     printf("****Dice roll game with 3 dices****\n\n");
  20.  
  21.     for(i=0; i<1; i++){
  22.         dice1 = (rand()%6) +1;
  23.         printf("dice1 = %d\n", dice1);
  24.  
  25.         dice2 = (rand()%6) +1;
  26.         printf("dice2 = %d\n", dice2);
  27.  
  28.         dice3 = (rand()%6) +1;
  29.         printf("dice3 = %d\n", dice3);
  30.  
  31.         sum1 = dice1+dice2+dice3;
  32.     }
  33.  
  34.     printf("The total from 3 dices is %d \n\n", sum1);
  35.     printf("What do you think your next roll will be higher(h),lower(l) or same(s) as the current total? \n\n");
  36.  
  37.     do{
  38.         printf("Enter (h),(l) or (s) to continue \n\n");
  39.         scanf(" %c", &input); //add a space between the quotes like " %c" not "%c"
  40.  
  41.         if( (input == 'l') || (input == 'h') || (input == 's') ){
  42.             input1 = 1;
  43.         }else{
  44.             input1 = 0;
  45.             printf("please read the text and try again\n\n");
  46.         }
  47.     }while(input1!=1);
  48.  
  49.     for(i=0; i<1; i++){
  50.         dice1 = (rand()%6) +1;
  51.         printf("dice1 = %d\n", dice1);
  52.  
  53.         dice2 = (rand()%6) +1;
  54.         printf("dice2 = %d\n", dice2);
  55.  
  56.         dice3 = (rand()%6) +1;
  57.         printf("dice3 = %d\n", dice3);
  58.     }
  59.  
  60.     sum2 = dice1+dice2+dice3;
  61.     if((sum1<sum2) && (input == 'h')){
  62.         printf("Congratz you guessed right total %d\n", sum2);
  63.         }else if ((sum1>sum2) && (input == 'l')){
  64.         printf("Congratz you guessed right total %d\n", sum2);
  65.         }else if ((sum1==sum2) && (input == 's')){
  66.         printf("Congratz you guessed right total %d\n", sum2);
  67.     }
  68.     else{
  69.         printf("you loose your total is %d\n", sum2);
  70.     }
  71.  
  72.     return 0;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement