Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* This program rolls two dice and presents the total. It then asks the user
- to guess if the next total will be higher, lower, or equal. It then rolls
- two more dice and tells the user how they did. */
- #include<stdio.h>
- #include<stdlib.h>
- #include<string.h>
- int main(void)
- {
- int dice1, dice2, total, total1= 0;
- char ans[25], dans[25];
- char higher[] = "HIGHER", lower[] = "LOWER", equal[] = "EQUAL";
- //the following 3 lines, throws the dice and adds them.
- dice1 = (rand() % 5) + 1;
- dice2 = (rand() % 5) + 1;
- total = dice1 + dice2;
- //the next few ask the question.
- printf("Will the next number be higher, lower or equal to %d ?n", total);
- puts("Type higher, lower or equal.");
- // scanf("&s", ans); //had to remove this line, because apparently we can't use &s to get the string input
- fgets(ans, 25, stdin);
- strcpy(dans, strupr(ans));
- //the next few throw the dice two more times
- dice1 = (rand() % 5) + 1;
- dice2 = (rand() % 5) + 1;
- total1 = dice1 + dice2;
- /*All of these check if the user input matches the actual output and
- then tells the user if he/she was right.*/
- printf("The upper string is %s.n", ans);
- if ((ans == higher) && (total1 > total))
- {
- printf("You're right, it is higher!n");
- }
- else if ((ans == lower) && (total1 < total))
- {
- printf("You're right, it is lower!n");
- }
- else if ((ans == equal) && (total1 = total))
- {
- printf("You're right. they are equal!n");
- }
- else
- {
- printf("Your prediction was wrong.n");
- }
- }
- strcpy(dans, strupr(ans));
- ^
- strcpy(dans, strupr(ans));
- ^~~~~~~~~~~
- ^
- if ((ans == higher) && (total1 > total))
- ^
- else if ((ans == lower) && (total1 < total))
- ^
- else if ((ans == equal) && (total1 = total))
Add Comment
Please, Sign In to add comment