Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<time.h>
- #include<stdlib.h>
- int rollDice() {
- return (rand() % 6) + 1;
- }
- int rollAndAdd() {
- return rollDice() + rollDice();
- }
- int main() {
- int sum, wins = 0, loses = 0;
- char cont = 'y';
- srand(time(NULL));
- printf("Press Enter to Start");
- getchar();
- while (cont == 'y' || cont == 'Y')
- {
- printf("Rolling dice!\n");
- sum = rollAndAdd();
- printf("The sum is:%d\n", sum);
- if (sum == 6 || sum == 9) {
- printf("You Won!\n");
- wins++;
- }
- else if (sum == 3 || sum == 12) {
- printf("Game Over!\n");
- loses++;
- }
- else {
- printf("Spare!\n");
- while (1) {
- printf("Press Enter to Continue");
- getchar();
- sum = rollAndAdd();
- printf("The sum is:%d\n", sum);
- if (sum == 6 || sum == 9) {
- printf("Game Over!\n");
- loses++;
- break;
- }
- else if (!(sum == 3 || sum == 12)) {
- printf("Spare!\n");
- printf("You Won!\n");
- wins++;
- break;
- }
- else {
- printf("Try Again!");
- }
- }
- }
- printf("Do you want to play again (Y/y:Yes, N/n:No):");
- scanf_s(" %c", &cont);
- getchar();
- while (cont != 'y' && cont != 'Y' && cont != 'n' && cont != 'N') {
- printf("Wrong Input!\nTry Again:");
- scanf_s(" %c", &cont);
- getchar();
- }
- }
- printf("You Won %d Times And Lost %d Times\nThanks for playing!", wins, loses);
- getchar();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement