-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroll_dice.c
More file actions
55 lines (44 loc) · 1.02 KB
/
roll_dice.c
File metadata and controls
55 lines (44 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int rollDice()
{
return rand() % 6 + 1;
}
int main()
{
srand(time(NULL));
int balance = 100; // Initial balance
int bet;
printf("Welcome to the Casino!\n");
while (balance > 0)
{
printf("\nYour current balance: %d\n", balance);
printf("Enter your bet (0 to quit): ");
scanf("%d", &bet);
if (bet == 0)
{
break;
}
if (bet > balance)
{
printf("Insufficient balance. Please place a lower bet.\n");
continue;
}
int diceRoll = rollDice();
printf("Dice roll: %d\n", diceRoll);
if (diceRoll == 6)
{
printf("Congratulations! You won!\n");
balance += bet;
}
else
{
printf("Sorry, you lost.\n");
balance -= bet;
}
}
printf("\nGame over. Your final balance: %d\n", balance);
printf("Thank you for playing!\n");
return 0;
}