Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # include <stdio.h>
- # include <time.h>
- int dado(int);
- int main(){
- int i, sum = 0, count = 0;
- while (sum == 0){
- printf("\nPress any key to roll dice.\n");
- getch();
- count += 1;
- for (i = 0; i < 2; i++)
- sum += dado(i);
- printf("Sum: %d\n\n", sum);
- if (sum == 7 || count > 21)
- printf("You lose!\n\n");
- break;
- switch (sum){
- case 7:
- printf("You won!\n\n");
- break;
- case 11:
- printf("You won!\n\n");
- break;
- case 2:
- printf("You lose!\n\n");
- sum = 0;
- break;
- case 3:
- printf("You lose!\n\n");
- sum = 0;
- break;
- case 12:
- printf("You lose!\n\n");
- sum = 0;
- break;
- default:
- printf("Try again!\n\n");
- sum = 0;
- break;
- }
- }
- printf("\nPress any key to exit...\n\n");
- getch();
- return 0;
- }
- int dado(offset){
- srand(time(NULL) + offset);
- return 1 + rand() % 6;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement