I have made this small text-based casino game in C++. How could I improve it? Be as picky as you'd like.
#include <iostream> #include <cstdlib> #include <ctime> using namespace std; // General functions void bankrupt(); // Roulette functions void roulette01(); void roulette02(); void rouletteWin(); void rouletteLoss(); // Slots functions void slots01(); void slots02(); // General variables int invalid = 1; int input; int dollars = 50; // Roulette variables int bet = 0; char cColour; int iColour; int actualColour; // Slots variables int randSlots01; int randSlots02; int randSlots03; int main() { srand (time(NULL)); while (invalid == 1) { system("cls"); cout << "\n Welcome to the Casino! What would you like to play?" << endl; cout << "\n 1. Roulette" << endl; cout << "\n 2. Slots" << endl; cout << "\n 3. Exit" << endl; cout << "\n> "; cin >> input; switch (input) { case 1: input = 1; roulette01(); case 2: slots01(); case 3: exit(0); default: cout << "\n That was invalid input!" << endl; cout << "\n "; system("pause"); invalid = 1; } } } void roulette01() { if (dollars <= 0) { bankrupt(); } system("cls"); cout << "\n Roulette" << endl; cout << "\n You have " << dollars << " dollars!" << endl; cout << "\n Enter 1 to place a bet. Enter 2 to exit to the main menu." << endl; cout << "\n> "; cin >> input; switch (input) { case 1: roulette02(); case 2: main(); } } void roulette02() { cout << "\n Enter how much you would like to bet." << endl; cout << "\n> "; cin >> bet; if (bet > dollars) { cout << "\n You don't have enough money for that bet!" << endl; cout << "\n "; system("pause"); roulette02(); } cout << "\n Would you like to bet on red or black?" << endl; cout << "\n Enter r for red. Enter b for black." << endl; cout << "\n> "; cin >> cColour; if (cColour == 'r') { iColour = 1; } else { iColour = 2; } actualColour = rand() % 2; if (actualColour == iColour) { rouletteWin(); } else { rouletteLoss(); } } void rouletteWin() { dollars = dollars + bet; cout << "\n You won " << bet << " dollars!" << endl; cout << "\n "; system("pause"); roulette01(); } void rouletteLoss() { dollars = dollars - bet; cout << "\n You lost " << bet << " dollars!" << endl; cout << "\n "; system("pause"); roulette01(); } void slots01() { if (dollars <= 0) { bankrupt(); } system("cls"); cout << "\n Slots" << endl; cout << "\n You have " << dollars << " dollars!" << endl; cout << "\n Enter 1 to play. Enter 2 to exit to the main menu." << endl; cout << "\n> "; cin >> input; switch (input) { case 1: slots02(); case 2: main(); } } void slots02() { randSlots01 = rand() % 3; randSlots02 = rand() % 3; randSlots03 = rand() % 3; if (randSlots01 == randSlots02 && randSlots02 == randSlots03) { dollars = dollars + 10; cout << "\n You won 10 dollars!" << endl; cout << "\n "; system("pause"); slots01(); } else { dollars--; cout << "\n You lost 1 dollar!" << endl; cout << "\n "; system("pause"); slots01(); } } void bankrupt() { dollars = 50; cout << "\n You have gone bankrupt! Time to start over." << endl; cout << "\n "; system("pause"); main(); }