About OOExpert Expertise I can answer questions about Object Oriented Programming, use of Design patterns, general C++ programming.
I am probably not the better to answer specific question about Windows API programming, MFC, OWL, ...
Experience 10 years of C++ programming in Automobile, Telecom, Defense.
Question I need to write a BASIC program for a slot machine.
The slot machine has three windows where the results appear. The slot machine will haev six results- cherry, orange, bell, joker, green, and bar. On any pull of the handle each of those results has an equal probability of occuring. If any two of the three are the same, the machine pays five dollars. If all three are teh same, we hit the fifty dollar jackpot. Also, it costs two dollars to play the machine.
I think I should use two arrays and the "random" function to generate the results for each pull of the handle. Also, I should generate numbers for one to six, then let one equal "cherry", two equal "orange" and so.
I need to start with a bankroll of ten dollars, and have the program play the machine either until I'm broke,, hit the jackpot, or my arms gets tired (fifty tries). For each try, I need to print the three results, the money for that try, and the amount in the bankroll.
Answer Hey,
Nice problem, but I don't see any question in your text ... I guess you want to know how I would solve that pb ...
First, I would create a class for the slot machine:
file cslotmachine.h
--------------------
#ifndef _CSLOTMACHINE_
#define _CSLOTMACHINE_
class CSlotMachine
{
public:
CSlotMachine();
~CSlotMachine();
unsigned short int GetResult(void);
protected:
private:
static const unsigned short int MaxValue = 6;
static const unsigned short int MaxSlot = 3;
};
//----------------------------------------------------
unsigned short int
CSlotMachine::GetResult(void)
{
unsigned short int result[3];
// get random result
for (unsigned short int i = 0; i < MaxSlot; i++)
{
double r = ( (double)rand() / (double)(RAND_MAX+1) );
result[i] = (unsigned short int) (r * (MaxValue + 1));
cout << " -" << result[i] << "- ";
}
cout << endl;
// analyse results
unsigned short int nb_match = 0;
} while (myBankRoll > 2); // if bank < 2, can't play anymore
system("PAUSE");
return 0;
}
This program compiled and tested OK using dev-C++ 4.9.8.4.
You can see that we don't care in the program about cherry, orange, ... we just want to know the result. You can add functions to match integers with possible result and display them in the CSlotMachine::GetResult function.