Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <ctype.h>
- #include <stdlib.h> // rand(), srand()
- #include <time.h> // time()
- int main()
- {
- int num[2],rNum=0;
- char usrinput[3];
- for(int j = 0; j < 2; j++)
- {
- if(j == 1)
- {
- printf("Do you think that you will get bigger total in next turn? (y/n)");
- do
- {
- usrinput[1] = getchar();
- }
- while(usrinput[1] != 'y' && usrinput[1] != 'n');
- usrinput[2] = getchar();
- }
- num[j] = 0;
- for(int i = 1; i <= 3; i++)
- {
- printf("Press enter to roll the dice (turn %d/3):", i);
- do
- {
- usrinput[0] = getchar();
- }
- while(usrinput[0] != '\n');
- srand(time(NULL));
- rNum = (rand()%6)+1;
- printf("The number you got is: %d\n", rNum);
- num[j] += rNum;
- }
- printf("\nTotal: %d\n\n", num[j]);
- }
- if((usrinput[1]=='y') && (num[1] > num[0])) printf("\n\nYou were right!\n");
- else if ((usrinput[1] == 'n') && (num[1] < num[0])) printf("\n\nYou were right2!\n");
- else if (num[1] == num[0]) printf("\n\nYou were wrong! Totals are of the same value!\n\n");
- else printf("\n\nYou were wrong!\n");
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement