Sunday, April 4, 2021

casino game project using c++ (POP) (3)

 #include<iostream>

#include<string>

#include<cstdlib>

#include<ctime>

using namespace std;

void rules();

int main()

{

string playername;

    int amount,bettingAmount,guess,dice;

    char choice;

    srand(time(0)); 

    cout<<"\t\t\t\t\t\t======================"<<endl;

    cout<<"\t\t\t\t\t\tWelcome to my  game:"<<endl;

    cout<<"\t\t\t\t\t\t======================"<<endl;

    cout << "Enter Your Name : ";

    cin>>playername;

    cout << "deposite the amount in your account for playing this game:";

    cin >> amount;

    do

    {

    system("cls");

        rules();

        cout<<"\n\nYour current balance is RS."<<amount <<endl;

        do

        {

            cout<<"enter money for bet : RS.";

            cin >> bettingAmount;

            if(bettingAmount > amount)

                cout << "Your betting amount is more than your current balance"<<endl;

                cout<<"please enter betting amount again:"<<endl;

        }while(bettingAmount > amount);

        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);

 

        dice = rand()%10 + 1; // Will hold the randomly generated integer between 1 and 10

    

        if(dice == guess)

        {

            cout << "\n\nGood Luck!! You won Rs." << bettingAmount *10;

            amount = amount + bettingAmount * 10;

        }

        else

        {

            cout << "Bad Luck this time !! You lost $ "<< bettingAmount <<"\n";

            amount = amount - bettingAmount;

        }

        cout << "The winning number was : " << dice <<endl;

        cout <<"your new balance is:"<< amount << "\n";

        if(amount == 0)

        {

            cout << "You have no money to play"<<endl;

            break;

        }

        cout<<"Do you want to play again (y/n)";

        cin >> choice;

    }while(choice =='Y'|| choice=='y');

    cout << "Thanks for playing game"<<endl;

    return 0;

}

void rules()

{

cout<<"\t\t\tRULES OF THIS GAME:"<<endl;

cout<<"\t\t1.choice a number between(1 to 10)"<<endl;

cout<<"\t\t2.if you guess a right number then you win a double of the amount that you bet in a game"<<endl;

cout<<"\t\t3.if you guess a wrong number then you lose a amount that you bet in a game"<<endl;

cout<<"\t\t4.please read all the above instruction carefully"<<endl;

cout<<"\t\t5.best of luck for this game"<<endl;

}

No comments:

Post a Comment