Welcome to Dream.In.Code
Click Here
Getting C++ Help is Easy!

Join 118,313 C++ Programmers for FREE! Ask your question and get quick answers from experts. There are 1,701 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



Slot Machine(not making random numbers)

 
Reply to this topicStart new topic

Slot Machine(not making random numbers)

lain
post 8 Aug, 2008 - 12:41 PM
Post #1


New D.I.C Head

*
Joined: 1 Aug, 2008
Posts: 7

I can't seem to get the wheels to display the random number could I get some input on this please


CODE
//Specification: This program simulates a three
//wheeled slot machine.  Each wheel will randomly
//display three numbers. When the numbers on the
//wheels match the user is awarded points.  The Slot
//machine requires the user to enter tokens to play.

#include <iostream>
#include <ctime>  

using namespace std;  

class slotMachine {
      private:
            int wheelA;
            int wheelB;
            int wheelC;
            double payOut;         //amount of $ won during the current turn
            double moneyInMachine; //total amount of $ in the machine
            double playersBalance; //the amount of $ not yet played
            double gameCost;       //the cost of one pull
            double moneyPaid;      //the money put in by user
      public:
             //prototypes
             slotMachine();
             bool displayMenu(void);
             bool pullHandle(void);
             void spinWheel(int &);
             double calculatePayout();
             void insertCoin(double );
             void displaySpinResults();
             int Random(int, int);
             void displayTotals();
};

int main(void) {
      //create a slot machine object
           slotMachine mySlot;

     //Start the slot machine game
     //Keep running until the user
     //decides to quit

      bool ok = true;
      while (ok){
          ok = mySlot.displayMenu();
      };

      return 0;
}

slotMachine::slotMachine () {
      //constructor, set the initial state
      //of all the properties

      srand((int) time(0));
      moneyInMachine = 100;
      moneyPaid = 0;
      payOut = 0;
      wheelA = 0;
      wheelB = 0;
      wheelC = 0;
      gameCost = 1;
}

bool slotMachine::displayMenu(void){
      //main menu, executes the command selected by the
      //user or returns a value to terminate game execution

      char choice = 'Z';

      bool continueGame = true;    

      cout << "\n\n(E)nd, (P)ull, P(A)Y, (T)otals :";
      cin >> choice;

      switch (choice) {
            case 'e':
            case 'E':  //stop game
                  continueGame = false;
                  break;
            case 'a':
            case 'A': //pay
                  double money;
                  cout << "\nIt's a dollar a pull!\n"
                        << "Put money into the machine $";
                  cin >> money;
                  insertCoin(money);
                  break;
            case 'p':
            case 'P': //pull
                  if (pullHandle()){
                    cout << endl << endl << endl;
                    displaySpinResults();
                    cout << "Payout $" << calculatePayout();
                  }
                  break;
           case 't':
           case 'T': //display totals
                  displayTotals();
                  break;
      }
      return continueGame;
}

bool slotMachine::pullHandle(void){
      //checks to see if there is enough user money
      //for a spin. If so, assigns a random value
     //to each wheel. Deducts the cost of one
     //pull from the users money.
     //returns true if the handle was pulled.
     //returns false if the handle could not be pulled                
    double moneyInMachine = 100;
    
    if (moneyInMachine >= gameCost){
        moneyInMachine = moneyInMachine - moneyPaid;
        cout << "You have \n" << moneyInMachine << endl;
    return true;
    }
    else (moneyInMachine < gameCost);
        cout << "You Must Insert More Money";
        return false;
}


void slotMachine::spinWheel(int &theWheel){
      //assign a random value to a wheel  
     theWheel = Random(1,3);
    
}

double slotMachine::calculatePayout(){
      //decides if the current wheel values merit a
      //payout and how much that payout should be.
      //deducts the total payout from the total
      //amount of money in the machine
    int jackPot = 1000;
    int goodJob = 10;
    int youLose = -5;
    

    if (wheelA == wheelB && wheelA == wheelC)
    {
    cout << "Jackpot!!! " << jackPot << endl;
    }

        else (wheelA == wheelB || wheelA == wheelC || wheelB == wheelC);
        {
            cout << "Good Job " << goodJob << endl;

            moneyInMachine = moneyInMachine + jackPot;
            moneyInMachine = moneyInMachine + goodJob;
        }
    return moneyInMachine;
}

void slotMachine::insertCoin(double amount = 0){
      //adds to the amount of money paid by the user
      //adds to the total money in the machine
    int moneyInMachine = 100;
    int moneyPaid = 0;

        moneyInMachine = moneyPaid + moneyInMachine;
}

void slotMachine::displaySpinResults(){
      //displays the value of the three wheels
            cout << "[" << wheelA << "] "
           << "[" << wheelB << "] "
           << "[" << wheelC << "] \n\n";
}

void slotMachine::displayTotals(){
     //displays the amount of money and number
        // of pulls the player has left
         cout << "\nMoney in Machine $" << slotMachine::moneyInMachine << endl;
     cout << "Pulls Left: " <<   slotMachine::moneyPaid / slotMachine::gameCost  << endl << endl;
}            

int slotMachine::Random(int lowerLimit, int upperLimit) {
    //returns a random number within the given boundary
    return 1 + rand() % (upperLimit - lowerLimit + 1);
}

User is offlineProfile CardPM

Go to the top of the page


NickDMax
post 8 Aug, 2008 - 01:50 PM
Post #2


2B||!2B

Group Icon
Joined: 18 Feb, 2007
Posts: 2,763



Thanked 37 times

Dream Kudos: 525
My Contributions


...as far as I can tell you never assign new values to the wheels. I mean you have a function for it (spinWheel()) but you never use it.

User is offlineProfile CardPM

Go to the top of the page

gabehabe
post 8 Aug, 2008 - 01:57 PM
Post #3


T3H R0XX0R!

Group Icon
Joined: 6 Feb, 2008
Posts: 3,520



Thanked 73 times

Dream Kudos: 2350

Expert In: (X)HTML, CSS, Batch Scripting, C, C++

My Contributions


Absolutely right.

You might wanna put a pause between generating each number, too.

Otherwise, since you use srand() and it seeds from the time, the time difference is so minimal that each wheel has the same number each time.

smile.gif
User is online!Profile CardPM

Go to the top of the page

lain
post 8 Aug, 2008 - 02:31 PM
Post #4


New D.I.C Head

*
Joined: 1 Aug, 2008
Posts: 7

lol oops I knew it had to be something simple
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 10/10/08 12:14PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month