Casino + dice game in C++
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<time.h>
void rules(); //function definition
void main()
{ //start braces for main function
double balance,amount,num,dice; //declare variables
char name[50],ch; //declare variables
srand(time(0));
clrscr();
cout<<"*****************************************************************************";
cout<<"\n\n\t\t WellCome To CASINO GAME\n\n";
cout<<"*****************************************************************************";
cout<<"\n\n\t Player Name: ";
cin.getline(name,80,'\n'); // to get name from the user
cout<<"\n\n\tAccount balance:";
cin>>balance; // to get balance from the user
//starting loops and conditions
do
{ //start braces from '1' do loop
clrscr();
rules();
cout<<"\n\n\t"<<name;
cout<<"\n\n\t Your current balance is Rs:"<<balance;
cout<<"\n";
do
{ //start braces from '2' do loop
cout<<"\n\n\n\tEnter Money To Bet:";
cin>>amount; //user enter money for bet
cout<<"\n";
if(amount>balance||amount<500)
{
cout<<"\n\t Your betting amount is more than your current balance..\n";
cout<<"\n\tRe-enter your data\n ";
}
else
break;
} //end braces from '1' do loop
while(1);
do //start braces from '3' do loop
{
cout<<"\tEnter your lucky number to bet between 1 to 10 :";
cin>>num;
if(num<=1||num>10)
cout<<"\tPlease check the number!! \n\n Enter Number between 1 to 10 \n\n Re-enter data: ";
else
break;
} //end braces from '3' do loop
while(1);
dice=1+rand()%10;
if(dice==num)
{
cout<<"\n\n\n\tGood Luck!! \n\n You won Rs:";
cout<<amount*2;
balance=balance+amount*2;
}
else
{
cout<<"\n\n\n\tBad Luck this time !! \n\n";
cout<<" \tYou lose Rs:"<<amount;
balance=balance-amount;
}
cout<<"\n\n\tThe winning number was : "<<dice;
cout<<"\n\n\t"<<name;
cout<<"\t You have Rs: "<<balance<<endl;
cout<<"\n\n Do you want to play (y/n)? ";
cin>>ch;
} //end braces from '1' do loop
while(ch=='Y'|| ch=='y');
clrscr();
cout<<"\n\n\n";
cout<<"\n\n\tTHANKS FOR COME TO CASINO...\n\n YOUR BALANCE AMOUNT IS RS:"<<balance<<"\n\n";
getch();
} ////end braces for main function
void rules()
{ // start braces for function definition
clrscr();
cout<<"\n\n";
cout<<"\n\t\tRULES OF THE GAME\n";
cout<<"\n\t 1. Choose any number between 1 to 10\n\t 2. If you win you will get 2 times of money you bet\n\t 3. If you bet on wrong number you will lose your betting amount\n\n";
cout<<endl;
} //end braces for function definition
0 comments:
Post a Comment