change the balance checking to bool

This commit is contained in:
Sebastian Ranoszek 2025-02-12 10:39:28 +01:00
parent bb0953bfe3
commit b33a371b83

View File

@ -28,6 +28,17 @@ void display_balance(){
cout << "Your current casino balance: " << balance << " NyscoCoins" << endl; 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() { void coinflip() {
srand(time(0)); // Seed the random number generator srand(time(0)); // Seed the random number generator
@ -39,9 +50,8 @@ void coinflip() {
cin >> bet_amount; cin >> bet_amount;
// Check if the user has enough balance // Check if the user has enough balance
if (bet_amount > balance) { if (!check_balance(bet_amount)) {
cout << "You don't have enough NyscoCoins! Please try again with a lower amount." << endl; return;
Sleep(3000);
} }
// Deduct the bet amount from the balance // 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: "; cout << "Enter the amount of money you want to bet on slots: ";
cin >> bet_amount; cin >> bet_amount;
if (bet_amount > balance) { if (!check_balance(bet_amount)) {
cout << "You don't have enough NyscoCoins! Please try again with a lower amount." << endl; return;
Sleep(3000);
} }
balance -= bet_amount; balance -= bet_amount;
@ -173,9 +182,8 @@ void blackjack() {
cout << "Enter your bet amount: "; cout << "Enter your bet amount: ";
cin >> bet_amount; cin >> bet_amount;
if (bet_amount > balance) { if (!check_balance(bet_amount)) {
cout << "You don't have enough NyscoCoins! Please try again with a lower amount." << endl; return;
Sleep(3000);
} }
balance -= bet_amount; balance -= bet_amount;
@ -244,15 +252,13 @@ void diceRoll() {
cout << "Enter the amount of money you want to bet on dice roll: "; cout << "Enter the amount of money you want to bet on dice roll: ";
cin >> bet_amount; cin >> bet_amount;
if (!check_balance(bet_amount)) {
return;
}
cout << "Guess the outcome: "; cout << "Guess the outcome: ";
cin >> 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) { if (outcome > 12) {
cout << "There are only two dices max number is 12" << endl; cout << "There are only two dices max number is 12" << endl;
Sleep(3000); Sleep(3000);
@ -309,10 +315,8 @@ void higherOrLower() {
cout << "Guess the outcome (H-Higher/L-Lower): "; cout << "Guess the outcome (H-Higher/L-Lower): ";
cin >> outcome; cin >> outcome;
if (bet_amount > balance) { if (!check_balance(bet_amount)) {
cout << "You don't have enough NyscoCoins! Please try again with a lower amount." << endl; return;
Sleep(3000);
higherOrLower();
} }
balance -= bet_amount; balance -= bet_amount;