P: 8
I need some help. I am getting an error of: local function definitions are illegal. What does this mean? Can anybody help me out a little? Thank you.
//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 award points. The Slot
//machine requires the user to enter tokens to play.
#include <iostream>
#include <ctime>
using std::cout;
using std::cin;
using std::endl;
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
//variable
int choice = 0;
//declare variables
char usersChoice = 'E';
bool continueGame = true;
//display menu opitions
cout << 'Welcome to Las Vegas Casino n';
cout << 'Please choose an option: n';
cout << '(E)nd, (P)ull, P(A)Y, (T)otals';
//get the input
cin >> usersChoice;
switch (usersChoice){
case 'E': //end game
continueGame = false;
break;
case 'A': //pay
continueGame = true;
//prompt user to pay
cout << 'Please enter $1.00. n' << gameCost << endl;
//get input
cout << 'Thank you for entering your money. n' << moneyPaid << endl;
break;
case 'P': //user pulls the handle
continueGame = true;
if (pullHandle()){
displaySpinResults();
calculatePayout();
break;
case 'T': //show the totals
continueGame = true;
displayTotals();
break;
}
return continueGame;
}
bool slotMachine::pullHandle(void){//local function defintions are illegal
//checks to see if there is money
//given by user then assigns a random value
//to each wheel. Deducts the cost of one
//pull from the users money.
double moneyInMachine = 100;
int wheelA = 1;
int wheelB = 2;
int wheelC = 3;
moneyInMachine = moneyInMachine - moneyPaid;
cout << 'You have n' << moneyInMachine << endl;
return true;
}
void slotMachine::spinWheel(int &theWheel){//local function definitions are illegal
//assign a random value to a wheel
int wheelA = 0;
int wheelB = 0;
int wheelC = 0;
wheelA;
{
wheelA = 1 + rand() % (3 - 1 + 1);
}
wheelB;
{
wheelB = 1 + rand() % (3 - 1 + 1);
}
wheelC;
{
wheelC = 1 + rand() % (3 - 1 + 1);
}
}
double slotMachine::calculatePayout(){// local function defintions are illegal
//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;
int wheelA = 0;
int wheelB = 0;
int wheelC = 0;
wheelA wheelB && wheelA wheelC;
{
cout << 'Jackpot!!!' << jackPot << endl;
}
wheelA wheelB || wheelA wheelC || wheelB wheelC;
{
cout << 'Good Job' << goodJob << endl;
}
jackPot;
{
moneyInMachine = moneyInMachine + jackPot;
}
goodJob;
{
moneyInMachine = moneyInMachine + goodJob;
}
return moneyInMachine;
}
void slotMachine::insertCoin(double amount = 0.0){ //local function definitions are illegal
//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
int wheelA = 0;
int wheelB = 0;
int wheelC = 0;
cout << 'First wheel shows: n' << wheelA << endl;
cout << 'Second wheel shows: n' << wheelB << endl;
cout << 'Third wheel shows: n' << wheelC << endl;
}
void slotMachine::displayTotals(){
//displays the total money in the machine and the number
//of pulls the user has left
cout << 'You have this much money left: $' << moneyInMachine << endl;
cout << 'You have this many turns left: ' << endl;
}
int slotMachine::Random(int lowerLimit, int upperLimit) {
//returns a random number within the given boundary
return 1 + rand() % (upperLimit - lowerLimit + 1);
}
}

This is a slot machine that resembles the real slot machines in the casinos. To create the project, you need to insert three image boxes into the form and program them so that they will display a set of three different pictures randomly when the user presses on the spin button. It involves a randomization process. Next, a timer needs to be incorporated into the procedures so that the program can produce animated effects. In addition, you can also insert the Microsoft Multimedia Control so that it can play sounds in synchronization with the spinning of the slot machine as well as when the player hits the jackpot. You can design any interface you like. We have created an interface as shown below:

  • This is a slot machine that resembles the real slot machines in the casinos. To create the project, you need to insert three image boxes into the form and program them so that they will display a set of three different pictures randomly when the user presses on the spin button. The Code for Spin Sub Procedure a = 1 + Int(Rnd.3) b = 1 + Int.
  • Today in C#, i will teach you how to create a program called Slot Machine Game. Now, let's start this tutorial! Let's start with creating a Windows Form Application in C# for this tutorial by following the following steps in Microsoft Visual Studio: Go to File, click New Project, and choose Windows Application.

(C) 'Scheme of chance' means a slot machine unless authorized under Chapter 3772. Of the Revised Code, lottery unless authorized under Chapter 3770. Of the Revised Code, numbers game, pool conducted for profit, or other scheme in which a participant gives a valuable consideration for a chance to win a prize, but does not include bingo, a skill.

The Interface

The Video Demo

Machine

Slot Machine Code C# Ro Ghoul

The Code for Spin Sub Procedure

The three random variables a, b and c will be randomly assigned the values 1, 2 and 3 using the RND function. Based on these three random numbers, three different pictures will be loaded into the three image boxes randomly using the LoadPicture method. Animated effects are created by putting the above procedure under the control of Timer1, which will call the spin procedure after every interval until it fulfills a certain condition. Sounds are also added using the Microsoft Multimedia Control to make the game more realistic and interesting. The amount won is controlled by the If...Then...End If statements

It is important that you define the correct path for the LoadPicture method, otherwise the program will not be able to run. For example, our path is C:VB programImagesgrape.gif, you need to create the necessary folders and have the necessary image file if you wish to copy the program directly. If you place the image file in a differently folder, you need to modify the path accordingly. For example, if your image file is in D:VB programImagesgrape.gif, then you need to modify the LoadPicture method to LoadPicture('D:VB programImagesgrape.gif').

If you wish to use our image files, you can download from the links below:

Slot Machine Code C# Bee Swarm Simulator

sound and the other for the jackpot sound. Below is the video demo of the slot machine simulator.

Slot Machine Code C#

Copyright©2008 Dr.Liew Voon Kiong. All rights reserved |Contact|Privacy Policy