Τετάρτη 14 Νοεμβρίου 2012

KENO


#include <cstdlib>
#include <ctime>
#include <iostream>
#include <vector>

using namespace std;

class keno
{
    private:
        double balance;

    public:
        keno(){balance = 0;}

        void putDeposit(double amount)
        {balance += amount;}

        void lostBet(double dollar)
        {balance -= dollar;}

        void won1SpotGame(double dollar)
         {balance += (dollar * 3);}

         void won5SpotGame(double dollar, int m)
         {if (m == 3)
         balance += dollar;
         else if (m == 4)
         balance += (dollar * 10);
         else if (m == 5)
         balance += (dollar * 800);}

         void won12SpotGame(double dollar, int hit)
         {if (hit == 6)
         balance += (dollar * 5);
         else if (hit == 7)
         balance += (dollar * 32);
         else if (hit == 8)
         balance += (dollar * 200);
         else if (hit == 9)
         balance += (dollar * 1000);
         else if (hit == 10)
         balance += (dollar * 5000);
         else if (hit == 11)
         balance += (dollar * 25000);
         else if (hit == 12)
         balance += (dollar * 100000);}

         double getBalance () const
        {return balance;}
};

void showMenu();

int main()
    {
char* lost = "Sorry, you didn't win.";
int choice, deposit;
int num1, num5[5], num12[12];
cout<<"Enter your deposit amount: ";
cin>>deposit;
if(!cin.eof() && cin.good())
{
if(deposit > 0)
{
keno A;
A.putDeposit(deposit);
do{
showMenu();
cin>>choice;
switch(choice)
{
case 1: // 1 spot game
{
        int match1 = 0;
        int bet;
        cout<<"How much do you want to bet? ";
        cin>>bet;
        cout<<"Enter 1 number: ";
        cin>>num1;
        cout<<endl;
        srand(time(NULL));
        vector<bool> Randoms(61,false);
        for(int i=1;i<21; i++) {
        int j = rand() % (80 - 1) + 1 + 1;
        if(Randoms[j]) {
                --i;
        } else {
            Randoms[j]=true;
            cout<<j<<" ";

            }

        if(j == num1)
        match1++;

        if(i % 5 == 0)
         cout<<endl;
        }
        cout<<endl;
        if(match1 == 0)
        {
        cout<<lost <<endl;
        A.lostBet(bet);
        cout<<"Current balance is $" <<A.getBalance() <<endl <<endl;
        }
        else
        {
        cout<<"You got 1 match\n";
        A.won1SpotGame(bet);
        cout<<"Current balance is $" <<A.getBalance() <<endl <<endl;
        }
        break;
}

case 2: // 5 spot game
        {
        int bet5;
        int match5 = 0;
        cout<<"How much do you want to bet? ";
        cin>>bet5;
        cout<<"Enter 5 numbers: ";
        for(int x=0; x<5; x++)
        cin>>num5[x];
        cout<<endl;
        srand(time(NULL));
        vector<bool> Randoms(61,false);
        for(int i=1; i<21; i++) {
        int r = rand() % (80 - 1) + 1 + 1;
        if(Randoms[r]) {
                --i;
        } else {
            Randoms[r]=true;
            cout<<r<<" ";
        }
        for(int c=0; c<5; c++)

        if(r == num5[c])
        match5++;

        if(i % 5 == 0)
         cout<<endl;
        }
        cout<<endl;
        if(match5 == 0 || match5 == 1 || match5 == 2)
        {
        cout<<lost <<endl;
        A.lostBet(bet5);
        cout<<"Current balance is $" <<A.getBalance() <<endl <<endl;
        }
        else
        {
        cout<<"You got " <<match5  <<" matches\n" <<endl;
        A.won5SpotGame(bet5, match5);
        cout<<"Current balance is $" <<A.getBalance() <<endl <<endl;
        }
        break;
        }

case 3: // 12 spot game
 {
        int bet12;
        int match12 = 0;
        cout<<"How much do you want to bet? ";
        cin>>bet12;
        cout<<"Enter 12 numbers: ";
        for(int x=0; x<12; x++)
        cin>>num12[x];
        cout<<endl;
        srand(time(NULL));
        vector<bool> Randoms(61,false);
        for(int i=1;i<21; i++) {
        int t = rand() % (80 - 1) + 1 + 1;
        if(Randoms[t]) {
                --i;
        } else {
            Randoms[t]=true;
            cout<<t<<" ";
        }
         for(int c=0; c<12; c++)

        if(t == num12[c])
        match12++;

        if(i % 5 == 0)
         cout<<endl;
        }
        cout<<endl;
        if(match12 == 0 || match12 == 1 || match12 == 2 ||
        match12 == 3 || match12 == 4 || match12 == 5)
        {
        cout<<lost <<endl;
        A.lostBet(bet12);
        cout<<"Current balance is $" <<A.getBalance() <<endl <<endl;
        }
        else
        {
        cout<<"You got " <<match12  <<" matches\n";
        A.won5SpotGame(bet12, match12);
        cout<<"Current balance is $" <<A.getBalance() <<endl <<endl;
        }
        break;
        }

case 4:  cout<<"Final balance is $" <<A.getBalance() <<endl;
         if(A.getBalance() < 0)
         cout<<"Better luck next time.\n";
         break;

default: cout<<"Invalid selection. Please choose an option 1-4.\n\n";
}
}while(choice != 4);
}
else
cout<<"Your deposit cannot be negative\n";
}
else
cout<<"Invalid input\n";

return 0;
}

void showMenu()
{
    cout<<"------KENO------\n";
    cout<<"1. 1 Spot Game\n";
    cout<<"2. 5 Spot Game\n";
    cout<<"3. 12 Spot Game\n";
    cout<<"4. Quit & Cash Out\n";
    cout<<"-----------------\n";
    cout<<"Enter your choice: ";
}