Guest User

Untitled

a guest
Feb 21st, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. /* This program rolls two dice and presents the total. It then asks the user
  2. to guess if the next total will be higher, lower, or equal. It then rolls
  3. two more dice and tells the user how they did. */
  4.  
  5. #include<stdio.h>
  6. #include<stdlib.h>
  7. #include<string.h>
  8.  
  9. int main(void)
  10. {
  11. int dice1, dice2, total, total1= 0;
  12. char ans[25], dans[25];
  13. char higher[] = "HIGHER", lower[] = "LOWER", equal[] = "EQUAL";
  14.  
  15. //the following 3 lines, throws the dice and adds them.
  16. dice1 = (rand() % 5) + 1;
  17. dice2 = (rand() % 5) + 1;
  18. total = dice1 + dice2;
  19.  
  20. //the next few ask the question.
  21. printf("Will the next number be higher, lower or equal to %d ?n", total);
  22. puts("Type higher, lower or equal.");
  23. // scanf("&s", ans); //had to remove this line, because apparently we can't use &s to get the string input
  24.  
  25. fgets(ans, 25, stdin);
  26. strcpy(dans, strupr(ans));
  27.  
  28. //the next few throw the dice two more times
  29. dice1 = (rand() % 5) + 1;
  30. dice2 = (rand() % 5) + 1;
  31. total1 = dice1 + dice2;
  32.  
  33. /*All of these check if the user input matches the actual output and
  34. then tells the user if he/she was right.*/
  35. printf("The upper string is %s.n", ans);
  36. if ((ans == higher) && (total1 > total))
  37. {
  38. printf("You're right, it is higher!n");
  39. }
  40. else if ((ans == lower) && (total1 < total))
  41. {
  42. printf("You're right, it is lower!n");
  43. }
  44. else if ((ans == equal) && (total1 = total))
  45. {
  46. printf("You're right. they are equal!n");
  47. }
  48. else
  49. {
  50. printf("Your prediction was wrong.n");
  51. }
  52.  
  53.  
  54.  
  55. }
  56.  
  57. strcpy(dans, strupr(ans));
  58.  
  59. ^
  60.  
  61. strcpy(dans, strupr(ans));
  62.  
  63. ^~~~~~~~~~~
  64.  
  65. ^
  66.  
  67. if ((ans == higher) && (total1 > total))
  68.  
  69. ^
  70.  
  71. else if ((ans == lower) && (total1 < total))
  72.  
  73. ^
  74.  
  75. else if ((ans == equal) && (total1 = total))
Add Comment
Please, Sign In to add comment