change the balance checking to bool
This commit is contained in:
parent
bb0953bfe3
commit
b33a371b83
42
main.cpp
42
main.cpp
@ -28,6 +28,17 @@ void display_balance(){
|
||||
cout << "Your current casino balance: " << balance << " NyscoCoins" << endl;
|
||||
}
|
||||
|
||||
bool check_balance(int bet_amount) {
|
||||
if (bet_amount > balance) {
|
||||
cout << "Insufficient funds. Please deposit more money." << endl;
|
||||
Sleep(3000);
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
void coinflip() {
|
||||
srand(time(0)); // Seed the random number generator
|
||||
|
||||
@ -39,9 +50,8 @@ void coinflip() {
|
||||
cin >> bet_amount;
|
||||
|
||||
// Check if the user has enough balance
|
||||
if (bet_amount > balance) {
|
||||
cout << "You don't have enough NyscoCoins! Please try again with a lower amount." << endl;
|
||||
Sleep(3000);
|
||||
if (!check_balance(bet_amount)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Deduct the bet amount from the balance
|
||||
@ -112,9 +122,8 @@ void slots() {
|
||||
cout << "Enter the amount of money you want to bet on slots: ";
|
||||
cin >> bet_amount;
|
||||
|
||||
if (bet_amount > balance) {
|
||||
cout << "You don't have enough NyscoCoins! Please try again with a lower amount." << endl;
|
||||
Sleep(3000);
|
||||
if (!check_balance(bet_amount)) {
|
||||
return;
|
||||
}
|
||||
|
||||
balance -= bet_amount;
|
||||
@ -173,9 +182,8 @@ void blackjack() {
|
||||
cout << "Enter your bet amount: ";
|
||||
cin >> bet_amount;
|
||||
|
||||
if (bet_amount > balance) {
|
||||
cout << "You don't have enough NyscoCoins! Please try again with a lower amount." << endl;
|
||||
Sleep(3000);
|
||||
if (!check_balance(bet_amount)) {
|
||||
return;
|
||||
}
|
||||
|
||||
balance -= bet_amount;
|
||||
@ -244,15 +252,13 @@ void diceRoll() {
|
||||
cout << "Enter the amount of money you want to bet on dice roll: ";
|
||||
cin >> bet_amount;
|
||||
|
||||
if (!check_balance(bet_amount)) {
|
||||
return;
|
||||
}
|
||||
|
||||
cout << "Guess the outcome: ";
|
||||
cin >> outcome;
|
||||
|
||||
if (bet_amount > balance) {
|
||||
cout << "You don't have enough NyscoCoins! Please try again with a lower amount." << endl;
|
||||
Sleep(3000);
|
||||
diceRoll();
|
||||
}
|
||||
|
||||
if (outcome > 12) {
|
||||
cout << "There are only two dices max number is 12" << endl;
|
||||
Sleep(3000);
|
||||
@ -309,10 +315,8 @@ void higherOrLower() {
|
||||
cout << "Guess the outcome (H-Higher/L-Lower): ";
|
||||
cin >> outcome;
|
||||
|
||||
if (bet_amount > balance) {
|
||||
cout << "You don't have enough NyscoCoins! Please try again with a lower amount." << endl;
|
||||
Sleep(3000);
|
||||
higherOrLower();
|
||||
if (!check_balance(bet_amount)) {
|
||||
return;
|
||||
}
|
||||
|
||||
balance -= bet_amount;
|
||||
|
Loading…
x
Reference in New Issue
Block a user