slot machine game in visual c++

hi i need help in making a non graphic slot machine program. I have to use object oriented programming but i am confused about what classes to use and to relate them.Also i have no idea how to implement the debug version. please help me.



In a real slot machine the player pulls a handle to rotate the reels that have pictures printed on them. Winning or losing is determined by which pictures line up with the pay line, a line in the middle of a viewing window. If each reel shows the same winning picture along the pay line, then the player wins (certain single images are sometimes winners as well). The payout (the amount the player wins) depends on what pictures fall along the pay line.

In this project, the reels will be labeled with numbers from 1 through 22. A user can place a bet for one or more of units of currency (N), up to 10. The payout is 2*N in every case the same number falls along the pay line in each wheel, EXCEPT for the following combinations where the payout is different:

1st Reel 2nd Reel 3rd Reel Payout
2            2              2          3*N
7            7               7         20*N
7            7             any         5*N
13        13              13          4*N
19        19              19          4*N

Upon placing a bet, your slot machine will "spin the wheels", print the outcome, the payout and the current player's balance.

Before the game begins the player will be prompted to enter the amount of currency (s)he has available to play on the slot machine. The slot machine always starts with 1,000 unites of currency.


Testing

To facilitate testing, the executable will accept an option --debug which will tell the application to print the slot machine balance every time messages are printed.
The spinning of the wheel will be simulated through the use of the srand and rand functions, which are found in cstdlib.
 the player's account balance should be updated, as well as the machine's, at the end of the round.




hassaanbAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Svetlin_PanayotovCommented:
Here's a sample class.I coded it in a hurry and I can't guarantee that everything will work fine - but it will be some help at least.

Svetlin

#include <iostream>
#include <math.h>


using namespace std;

class CSlotMachine
{
private:
      int iMachineBalance, iPlayerBalance, iBet, iBetOn;
      bool bDebug;

protected:
      void DoBet();
      void Spin();

public:
      CSlotMachine(int iNewBalance, bool bIsInDebug = false)      //constructor
      {
            iMachineBalance = 1000;      //the machine always starts with 1000
            iPlayerBalance = iNewBalance;
            bDebug = bIsInDebug;
      }

      ~CSlotMachine()
      {
            //Well...nothing to do here
      }

      void Run()
      {
            this->DoBet();
            this->Spin();
      }

      int GetPlayerBalance()
      {
            return iPlayerBalance;
      }

};


void CSlotMachine::DoBet()
{
      cout << "Bet on which number?";
      cin >> iBetOn;
      cout << "How many?";
      cin >> iBet;
      if (iBet > iPlayerBalance)
      {
            cout << "You don't have " << iBet << "$";
            //Bet = what's left
            iBet = iPlayerBalance;
      }
}

void CSlotMachine::Spin()
{
      srand(23);
      int iFirst = 100;
      int iSecond = 100;
      int iThird = 100;
      int iPayout;
      //Generate numbers
      
      while (iFirst > 22)
            iFirst = rand();
      
      while (iSecond > 22)
            iSecond = rand();
      
      while (iThird > 22)
            iThird = rand();

      cout << iFirst << "\t" << iSecond << "\t" << iThird << endl;

      if (iFirst == iSecond == iThird == iBetOn)
      {
            switch (iFirst)      //check for those special cases
            {
            case (2):
                  iPayout = 3*iBet;
                  break;

            case (7):
                  iPayout = 20*iBet;
                  break;

            case (13):
                  iPayout = 4*iBet;
                  break;

            case (19):
                  iPayout = 4*iBet;
                  break;
            
            default:
                  iPayout = 2*iBet;
                  break;
            }

            cout << "You won " << iPayout << endl;
            iPlayerBalance += iPayout;
            iMachineBalance -= iPayout;
      }
      else
      {
            if (iFirst == iSecond == iBetOn == 7)
            {
                  //Special case
                  iPayout = 5*iBet;
                  cout << "You won " << iPayout << endl;
                  iPlayerBalance += iPayout;
                  iMachineBalance -= iPayout;
            }
            cout << "You lose" << endl;
            iPlayerBalance -= iBet;
      }

      cout << "Your balance is : " << iPlayerBalance << endl;

      if (bDebug)
            cout << "DEBUG: Machine balance = " << iMachineBalance;
}
0
hassaanbAuthor Commented:
i am getting this error


--------------------Configuration: slot machine - Win32 Debug--------------------
Linking...
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/slot machine.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

slot machine.exe - 2 error(s), 0 warning(s)
when i add int main() i get
--------------------Configuration: slot machine - Win32 Debug--------------------
Compiling...
slot machine.cpp
C:\Documents and Settings\nasihas\slot machine\slot machine.cpp(11) : error C2601: 'DoBet' : local function definitions are illegal
C:\Documents and Settings\nasihas\slot machine\slot machine.cpp(25) : error C2601: 'Spin' : local function definitions are illegal
Error executing cl.exe.

slot machine.exe - 2 error(s), 0 warning(s)
0
Svetlin_PanayotovCommented:
Well...you know - there's a main() in all console apps :)
I sent you only the class - and the <include>'s it needs - and I suppose that you should be able to add your own main()
and use the class.OK.Here's everything.

#include "stdafx.h"

#include <iostream>
#include <math.h>


using namespace std;


class CSlotMachine
{
private:
     int iMachineBalance, iPlayerBalance, iBet, iBetOn;
     bool bDebug;

protected:
     void DoBet();
     void Spin();

public:
     CSlotMachine(int iNewBalance, bool bIsInDebug = false)     //constructor
     {
          iMachineBalance = 1000;     //the machine always starts with 1000
          iPlayerBalance = iNewBalance;
          bDebug = bIsInDebug;
     }

     ~CSlotMachine()
     {
          //Well...nothing to do here
     }

     void Run()
     {
          this->DoBet();
          this->Spin();
     }

     int GetPlayerBalance()
     {
          return iPlayerBalance;
     }

};


void CSlotMachine::DoBet()
{
     cout << "Bet on which number?";
     cin >> iBetOn;
     cout << "How many?";
     cin >> iBet;
     if (iBet > iPlayerBalance)
     {
          cout << "You don't have " << iBet << "$";
          //Bet = what's left
          iBet = iPlayerBalance;
     }
}

void CSlotMachine::Spin()
{
     srand(23);
     int iFirst = 100;
     int iSecond = 100;
     int iThird = 100;
     int iPayout;
     //Generate numbers
     
     while (iFirst > 22)
          iFirst = rand();
     
     while (iSecond > 22)
          iSecond = rand();
     
     while (iThird > 22)
          iThird = rand();

     cout << iFirst << "\t" << iSecond << "\t" << iThird << endl;

     if (iFirst == iSecond == iThird == iBetOn)
     {
          switch (iFirst)     //check for those special cases
          {
          case (2):
               iPayout = 3*iBet;
               break;

          case (7):
               iPayout = 20*iBet;
               break;

          case (13):
               iPayout = 4*iBet;
               break;

          case (19):
               iPayout = 4*iBet;
               break;
         
          default:
               iPayout = 2*iBet;
               break;
          }

          cout << "You won " << iPayout << endl;
          iPlayerBalance += iPayout;
          iMachineBalance -= iPayout;
     }
     else
     {
          if ((iFirst == iSecond) && (iSecond == iBetOn) && (iBetOn == 7))
          {
               //Special case
               iPayout = 5*iBet;
               cout << "You won " << iPayout << endl;
               iPlayerBalance += iPayout;
               iMachineBalance -= iPayout;
          }
          cout << "You lose" << endl;
          iPlayerBalance -= iBet;
     }

     cout << "Your balance is : " << iPlayerBalance << endl;

     if (bDebug)
          cout << "DEBUG: Machine balance = " << iMachineBalance;
}


int main(int argc, char* argv[])
{
      CSlotMachine* oMachine = new CSlotMachine(300,false);

      int iTest, iTestTwo;

      
      while (oMachine->GetPlayerBalance() > 0)
            oMachine->Run();
      
      delete oMachine;
      return 0;
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

hassaanbAuthor Commented:
ok great
but it doesn't generate random numbers and i am suppose to break it in slot machine and spin classes. i don't get what RUN is.
0
Svetlin_PanayotovCommented:
Well...I don't get what you mean by "doesn't generate random numbers"...
And about Run() - it sort of wrapper for the private methods - if you for example decide to extend the class - write your private method and just add it in Run().It's sort of personal choice - I prefer to design my classes like that.
Svetlin
0
hassaanbAuthor Commented:
what i mean is that it generates same number every time i place a bet.If i seed it with time null instead of 23 it always makes you win at 0. Also i don't need to ask the user to select a number
so the machine can generate any number from 1-21. i only need them to place a bet between 1-10.
0
Svetlin_PanayotovCommented:
Well I hope you can fix that yourself.
0
Svetlin_PanayotovCommented:
For the random numbers - it can be something like

srand( time( NULL ) );
iFirst = rand();
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual C++.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.