//**************************************************************************************************************// // This code has been provided by TutorialsArt.com // Distribution of the code is permitted if and only if you do not delete these lines. //**************************************************************************************************************// #include <iostream> #include <string> // Needed to use strings #include <cstdlib> // Needed to use random numbers #include <ctime> using namespace std; void Drawa_Line_fn(int n, char symbol); void game_rules(); int main() { string playerName; int Balance_amount; // hold player's balance Balance_amount int bet_amount; int guess; int roll_dice; // hold computer generated number char choices; srand(time(0)); // "Seed" the random generator Drawa_Line_fn(60,'_'); cout << "\n\n\n\t\tCASINO GAME\n\n\n\n"; Drawa_Line_fn(60,'_'); cout << "\n\nEnter Your Name : "; getline(cin, playerName); cout << "\n\nEnter Deposit Balance_amount to play game : $"; cin >> Balance_amount; do { system("cls"); game_rules(); cout << "\n\nYour current balance is $ " << Balance_amount << "\n"; // Get player's betting Balance_amount do { cout <<playerName<<", enter money to bet : $"; cin >> bet_amount; if(bet_amount > Balance_amount) cout << "Your betting Balance_amount is more than your current balance\n" <<"\nRe-enter data\n "; }while(bet_amount > Balance_amount); // Get player's numbers do { cout << "Guess your number to bet between 1 to 10 :"; cin >> guess; if(guess <= 0 || guess > 10) cout << "Please check the number!! should be between 1 to 10\n" <<"\nRe-enter data\n "; }while(guess <= 0 || guess > 10); roll_dice = rand()%10 + 1; // Will hold the randomly generated integer between 1 and 10 if(roll_dice == guess) { cout << "\n\nGood Luck!! You won Rs." << bet_amount * 10; Balance_amount = Balance_amount + bet_amount * 10; } else { cout << "Bad Luck this time !! You lost $ "<< bet_amount <<"\n"; Balance_amount = Balance_amount - bet_amount; } cout << "\nThe winning number was : " << roll_dice <<"\n"; cout << "\n"<<playerName<<", You have $ " << Balance_amount << "\n"; if(Balance_amount == 0) { cout << "You have no money to play "; break; } cout << "\n\n-->Do you want to play again (y/n)? "; cin >> choices; }while(choices =='Y'|| choices=='y'); cout << "\n\n\n"; Drawa_Line_fn(70,'='); cout << "\n\nThanks for playing game. Your balance Balance_amount is $ " << Balance_amount << "\n\n"; Drawa_Line_fn(70,'='); return 0; } void Drawa_Line_fn(int n, char symbol) { for(int i=0; i<n; i++) cout << symbol; cout << "\n" ; } void game_rules() { system("cls"); cout << "\n\n"; Drawa_Line_fn(80,'-'); cout << "\t\tRULES OF THE GAME\n"; Drawa_Line_fn(80,'-'); cout << "\t1. Choose any number between 1 to 10\n"; cout << "\t2. If you win you will get 10 times of money you bet\n"; cout << "\t3. If you bet on wrong number you will lose your betting Balance_amount\n\n"; Drawa_Line_fn(80,'-'); } // END OF PROGRAM