# Casino Royale Game in C++

This is a guessing game called Casino Royale, created in C++ language which works on your luck!! Try and Win!!

Hello everyone,

As we all know, C++ is a very good and simple programming language that can be used to develop some games. So here I have made another interesting game called "Casino Royale".

Casino Royale is a game where a player plays by his/her luck. The player has to put some of his/her money on stake and choose a random number. If the computer chose a random number that matches the player's number, the player wins and gets an increased amount as his balance. But on the opposite side, if the player is failed by his/her luck, then the entire betting amount is lost. Therefore the game has its perks and downsides.

Here in this code, a function, Rules() is used to print some option on the player's screen. Further in the main function,  we take input by the player i.e., his/her name, current balance, betting amount, his/her random guess number, and a switch option to switch between cases.

The srand(time(0)) is used to set the seed value which does not repeat. At the first step, we check if the betting amount is more than the balance, then an error message is displayed else we take the player's lucky number as input, but this number should be between 1 and 100.

If the player's number matches with the computer-generated number, then the player wins and received the increased amount such that :

balance = balance + bet_amt * 100;

But if the player fails in his luck, then the amount is deducted, such as:

balance = balance - bet_amt;

The game continues, until a player exits the game or the player loses all his/her money and balance becomes 0. The complete code is as follows:

#include
#include  //  to use strings
#include  //  to use random numbers
#include
using namespace std;
void Rules()
{
system("cls");
cout << "\t\t*****CASINO NUMBER GUESSING RULES!*****"<<endl;
cout << "\t1. Choose a number between 1 to 10"<<endl;
cout << "\t2. Winner gets 10 times of the money bet "<<endl;
cout << "\t3. Bet Wrong, and you lose the entire amount you bet"<<endl<<endl;
}
int main()
{
string name; //takes name of player
int balance; // stores player's balance
int bet_amt; // gets the betting amount
int guess; // takes the random guess
int roll; // stores the random number
char option; //to switch
srand(time(0)); // "Seed" the random generator
cout << "\n\t\t***********WELCOME TO CASINO ROYALE***********\n\n";
cin>>name;
cout << "\n\n Enter the starting balance to start game : ";
cin >> balance;
do
{
Rules();
cout << "\n\n Your current balance is " << balance <<endl;
// Get player's betting balance
do
{
cout<< name<<", please enter amount to bet : ";
cin >> bet_amt;
if(bet_amt > balance)
cout << "Betting balance should be less than the current balance! \n\n"<<"You have to re-enter amount"<<endl;

}while(bet_amt > balance);
// Get player's guessing numbers
do
{
cout << "Guess a betting number between 1 & 100 :";
cin >> guess;
if(guess <= 0 || guess > 100)
cout << "\n Enter number between 1 to 10 \n"<<"Re-enter number:"<<endl;
}while(guess <= 0 || guess > 100);
roll = rand()%100 + 1;
if(roll == guess)
{
cout << "\n\n You are lucky!! You have won Rs." << bet_amt * 100;
balance = balance + bet_amt * 100;
}
else
{
cout << "Sorry, better luck next time !! You lost  "<< bet_amt<<endl;
balance = balance - bet_amt;
}
cout << "\nThe winning number was : " << roll <<"\n";
cout << "\n"<<name<<", You have balance of " << balance << endl;
if(balance == 0)
{
cout<< "You have no money left to play ";
break;
}
cout << "\n\n *Do you want to play again (y/n)?* ";
cin >> option;
}while(option =='Y'|| option=='y');
cout <<endl<<endl<<endl;
cout << "\n\n Thanks for playing the game. Your current balance is: " << balance <<endl<<endl;
return 0;
}

Sample Input and Output:

***********WELCOME TO CASINO ROYALE***********

Enter the starting balance to start game : 5000
*****CASINO NUMBER GUESSING RULES!*****
1. Choose a number between 1 to 10
2. Winner gets 10 times of the money bet
3. Bet Wrong, and you lose the entire amount you bet

Sanskriti, please enter amount to bet : 2000
Guess a betting number between 1 & 100 :24
Sorry, better luck next time !! You lost  2000

The winning number was : 11

Sanskriti, You have balance of 3000

*Do you want to play again (y/n)?* y
*****CASINO NUMBER GUESSING RULES!*****
1. Choose a number between 1 to 10
2. Winner gets 10 times of the money bet
3. Bet Wrong, and you lose the entire amount you bet

Sanskriti, please enter amount to bet : 100000
Betting balance should be less than the current balance!

You have to re-enter amount
Sanskriti, please enter amount to bet : 1000
Guess a betting number between 1 & 100 :28
Sorry, better luck next time !! You lost  1000

The winning number was : 93

Sanskriti, You have balance of 2000

*Do you want to play again (y/n)?* n

Thanks for playing the game. Your current balance is: 2000