473,804 Members | 2,134 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

slot machine in c++

8 New Member
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.
Expand|Select|Wrap|Line Numbers
  1. //Specification: This program simulates a three
  2. //wheeled slot machine.  Each wheel will randomly
  3. //display three numbers. When the numbers on the 
  4. //wheels match the user is award points.  The Slot
  5. //machine requires the user to enter tokens to play. 
  6. #include <iostream>
  7. #include <ctime>  
  8. using std::cout;
  9. using std::cin;
  10. using std::endl;
  11.  
  12. class slotMachine {    
  13. private:    
  14.     int wheelA;    
  15.     int wheelB;    
  16.     int wheelC;    
  17.     double payOut;         //amount of $ won during the current turn    
  18.     double moneyInMachine; //total amount of $ in the machine    
  19.     double playersBalance; //the amount of $ not yet played    
  20.     double gameCost;       //the cost of one pull    
  21.     double moneyPaid;      //the money put in by user    
  22. public:    
  23. //prototypes    
  24.            slotMachine();    
  25.            bool displayMenu(void);    
  26.            bool pullHandle(void);    
  27.            void spinWheel(int &);    
  28.            double calculatePayout();    
  29.            void insertCoin(double );    
  30.            void displaySpinResults();    
  31.            int Random(int, int);    
  32.            void displayTotals();
  33. }; 
  34. int main(void) {    
  35. //create a slot machine object 
  36.            slotMachine mySlot; 
  37.      //Start the slot machine game    
  38. //Keep running until the user    
  39. //decides to quit 
  40.     bool ok = true;    
  41. while (ok){    
  42.     ok = mySlot.displayMenu();    
  43.       return 0; 
  44. slotMachine::slotMachine () {    
  45. //constructor, set the initial state    
  46. //of all the properties 
  47.     srand((int) time(0));    
  48. moneyInMachine = 100;    
  49. moneyPaid = 0;    
  50. payOut = 0;    
  51. wheelA = 0;    
  52. wheelB = 0;    
  53. wheelC = 0;    
  54. gameCost = 1;
  55. bool slotMachine::displayMenu(void){    
  56. //main menu, executes the command selected by the    
  57. //user or returns a value to terminate game execution    
  58.  
  59.     //variable
  60.     int choice = 0;
  61.      //declare variables
  62.        char usersChoice = 'E';
  63.        bool continueGame = true;
  64.  
  65.        //display menu opitions
  66.        cout << "Welcome to Las Vegas Casino \n";
  67.        cout << "Please choose an option: \n";
  68.        cout << "(E)nd, (P)ull, P(A)Y, (T)otals"; 
  69.        //get the input
  70.        cin >> usersChoice;
  71.  
  72.        switch (usersChoice){
  73.            case 'E': //end game
  74.                continueGame = false;
  75.                break;
  76.            case 'A': //pay
  77.                continueGame = true;
  78.                //prompt user to pay
  79.                cout << "Please enter $1.00. \n" << gameCost << endl;
  80.                //get input
  81.                cout << "Thank you for entering your money. \n" << moneyPaid << endl;
  82.                break;
  83.            case 'P': //user pulls the handle
  84.                continueGame = true;
  85.                if (pullHandle()){
  86.                     displaySpinResults();
  87.                     calculatePayout(); 
  88.                        break;
  89.            case 'T':  //show the totals
  90.                continueGame = true;
  91.                displayTotals();
  92.                break;           
  93.        }
  94.        return continueGame;
  95. }
  96.  
  97. bool slotMachine::pullHandle(void){//local function defintions are illegal    
  98. //checks to see if there is money     
  99. //given by user then assigns a random value    
  100. //to each wheel. Deducts the cost of one    
  101. //pull from the users money. 
  102.     double moneyInMachine = 100;
  103.     int wheelA = 1;
  104.     int wheelB = 2;
  105.     int wheelC = 3;
  106.  
  107.         moneyInMachine = moneyInMachine - moneyPaid; 
  108.         cout << "You have \n" << moneyInMachine << endl;
  109.  
  110.         return true;
  111.  
  112. }
  113. void slotMachine::spinWheel(int &theWheel){//local function definitions are illegal    
  114.     //assign a random value to a wheel 
  115.     int wheelA = 0;
  116.     int wheelB = 0;
  117.     int wheelC = 0;
  118.  
  119.     wheelA;
  120.     {
  121.         wheelA = 1 + rand() % (3 - 1 + 1);
  122.     }    
  123.     wheelB;
  124.     {
  125.         wheelB = 1 + rand() % (3 - 1 + 1);
  126.     }
  127.     wheelC;
  128.     {
  129.         wheelC = 1 + rand() % (3 - 1 + 1);
  130.     }
  131.  
  132.  
  133. double slotMachine::calculatePayout(){// local function defintions are illegal
  134. //decides if the current wheel values merit a     
  135. //payout and how much that payout should be.    
  136. //deducts the total payout from the total    
  137. //amount of money in the machine 
  138.     int jackPot = 1000;
  139.     int goodJob = 10;
  140.     int youLose = -5;
  141.     int wheelA = 0;
  142.     int wheelB = 0;
  143.     int wheelC = 0;
  144.  
  145.     wheelA == wheelB && wheelA == wheelC;
  146.     {
  147.         cout << "Jackpot!!!" << jackPot << endl;
  148.     }
  149.  
  150.     wheelA == wheelB || wheelA == wheelC || wheelB == wheelC;
  151.         {
  152.             cout << "Good Job" << goodJob << endl;
  153.         }
  154.  
  155.     jackPot;
  156.     {
  157.         moneyInMachine = moneyInMachine + jackPot;
  158.     }
  159.  
  160.     goodJob;
  161.     {
  162.         moneyInMachine = moneyInMachine + goodJob;
  163.     }
  164.     return moneyInMachine;
  165.  
  166. void slotMachine::insertCoin(double amount = 0.0){    //local function definitions are illegal
  167. //adds to the amount of money paid by the user    
  168. //adds to the total money in the machine 
  169.     int moneyInMachine = 100;
  170.     int moneyPaid = 0;
  171.  
  172.     moneyInMachine = moneyPaid + moneyInMachine;
  173.  
  174.  
  175.  
  176. void slotMachine::displaySpinResults(){    
  177. //displays the value of the three wheels
  178.     int wheelA = 0;
  179.     int wheelB = 0;
  180.     int wheelC = 0;    
  181.  
  182.     cout << "First wheel shows: \n" << wheelA << endl;
  183.     cout << "Second wheel shows: \n" << wheelB << endl;
  184.     cout << "Third wheel shows: \n" << wheelC << endl;
  185.  
  186.  
  187. void slotMachine::displayTotals(){    
  188. //displays the total money in the machine and the number    
  189. //of pulls the user has left 
  190.     cout << "You have this much money left: $" << moneyInMachine << endl;
  191.     cout << "You have this many turns left: " << endl;
  192.  
  193. }         
  194. int slotMachine::Random(int lowerLimit, int upperLimit) {
  195.     //returns a random number within the given boundary    
  196. return 1 + rand() % (upperLimit - lowerLimit + 1); 
  197. }
  198.  
  199. }
Oct 7 '07 #1
6 27427
oler1s
671 Recognized Expert Contributor
One of the instructions in the forum guidelines, which you like all other smart people read, says to use CODE tags. Why didn't you use them?

And, uh, mind telling us the exact error displayed by your compiler? Yes, that means you actually have to copy/paste it.
Oct 7 '07 #2
dirtysouth6975
8 New Member
I am sorry, I am new at this. What is CODE tag? My errors were at slotMachine::ca lculatePayout, ""displaySpinRe sults, ""displayTotals , "" insertCoin, ""pullHandl e, ""Random, and ""spinWheel .
Oct 7 '07 #3
oler1s
671 Recognized Expert Contributor
If you read the guidelines, it would say that surrounding all code, you should put [CODE ] and [/code]. This preserves formatting and indentation in code, which means we can actually read it and help you.

And, I don't think you quite understand what I mean by copy-paste the error messages. There's an error because your compiler says something. You need to copy and paste those error messages exactly. Not tell me what functions they refer to, or what you think they mean. I can't diagnose your problem until I see precisely what those error messages say.
Oct 7 '07 #4
dirtysouth6975
8 New Member
Error 3 error C2601: 'slotMachine::c alculatePayout' : local function definitions are illegal c:\documents and settings\michel e barrett\my documents\visua l studio 2005\projects\s lot machine\slot machine\slot machine.cpp 137
Error 5 error C2601: 'slotMachine::d isplaySpinResul ts' : local function definitions are illegal c:\documents and settings\michel e barrett\my documents\visua l studio 2005\projects\s lot machine\slot machine\slot machine.cpp 182
Error 6 error C2601: 'slotMachine::d isplayTotals' : local function definitions are illegal c:\documents and settings\michel e barrett\my documents\visua l studio 2005\projects\s lot machine\slot machine\slot machine.cpp 194
Error 4 error C2601: 'slotMachine::i nsertCoin' : local function definitions are illegal c:\documents and settings\michel e barrett\my documents\visua l studio 2005\projects\s lot machine\slot machine\slot machine.cpp 171
Error 1 error C2601: 'slotMachine::p ullHandle' : local function definitions are illegal c:\documents and settings\michel e barrett\my documents\visua l studio 2005\projects\s lot machine\slot machine\slot machine.cpp 100
Error 7 error C2601: 'slotMachine::R andom' : local function definitions are illegal c:\documents and settings\michel e barrett\my documents\visua l studio 2005\projects\s lot machine\slot machine\slot machine.cpp 201
Error 2 error C2601: 'slotMachine::s pinWheel' : local function definitions are illegal c:\documents and settings\michel e barrett\my documents\visua l studio 2005\projects\s lot machine\slot machine\slot machine.cpp 116
Oct 7 '07 #5
dirtysouth6975
8 New Member
And for the code tag, I need to type[code] where indention needs to go. I just need clarification.
Oct 7 '07 #6
oler1s
671 Recognized Expert Contributor
Because you are new, I gave you some slack.

Here is the code formatted:

Expand|Select|Wrap|Line Numbers
  1. //Specification: This program simulates a three
  2. //wheeled slot machine. Each wheel will randomly
  3. //display three numbers. When the numbers on the
  4. //wheels match the user is award points. The Slot
  5. //machine requires the user to enter tokens to play.
  6. #include <iostream>
  7. #include <ctime>
  8. using std::cout;
  9. using std::cin;
  10. using std::endl;
  11.  
  12. class slotMachine
  13. {
  14. private:
  15.     int wheelA;
  16.     int wheelB;
  17.     int wheelC;
  18.     double payOut; //amount of $ won during the current turn
  19.     double moneyInMachine; //total amount of $ in the machine
  20.     double playersBalance; //the amount of $ not yet played
  21.     double gameCost; //the cost of one pull
  22.     double moneyPaid; //the money put in by user
  23. public:
  24. //prototypes
  25.     slotMachine();
  26.     bool displayMenu(void);
  27.     bool pullHandle(void);
  28.     void spinWheel(int &);
  29.     double calculatePayout();
  30.     void insertCoin(double );
  31.     void displaySpinResults();
  32.     int Random(int, int);
  33.     void displayTotals();
  34. };
  35. int main(void)
  36. {
  37. //create a slot machine object
  38.     slotMachine mySlot;
  39. //Start the slot machine game
  40. //Keep running until the user
  41. //decides to quit
  42.     bool ok = true;
  43.     while (ok)
  44.     {
  45.         ok = mySlot.displayMenu();
  46.     }
  47.     return 0;
  48. }
  49. slotMachine::slotMachine ()
  50. {
  51. //constructor, set the initial state
  52. //of all the properties
  53.     srand((int) time(0));
  54.     moneyInMachine = 100;
  55.     moneyPaid = 0;
  56.     payOut = 0;
  57.     wheelA = 0;
  58.     wheelB = 0;
  59.     wheelC = 0;
  60.     gameCost = 1;
  61. }
  62. bool slotMachine::displayMenu(void)
  63. {
  64. //main menu, executes the command selected by the
  65. //user or returns a value to terminate game execution
  66.  
  67. //variable
  68.     int choice = 0;
  69. //declare variables
  70.     char usersChoice = 'E';
  71.     bool continueGame = true;
  72.  
  73. //display menu opitions
  74.     cout << "Welcome to Las Vegas Casino \n";
  75.     cout << "Please choose an option: \n";
  76.     cout << "(E)nd, (P)ull, P(A)Y, (T)otals";
  77. //get the input
  78.     cin >> usersChoice;
  79.  
  80.     switch (usersChoice)
  81.     {
  82.     case 'E': //end game
  83.         continueGame = false;
  84.         break;
  85.     case 'A': //pay
  86.         continueGame = true;
  87. //prompt user to pay
  88.         cout << "Please enter $1.00. \n" << gameCost << endl;
  89. //get input
  90.         cout << "Thank you for entering your money. \n" << moneyPaid << endl;
  91.         break;
  92.     case 'P': //user pulls the handle
  93.         continueGame = true;
  94.         if (pullHandle())
  95.         {
  96.             displaySpinResults();
  97.             calculatePayout();
  98.             break;
  99.         case 'T': //show the totals
  100.             continueGame = true;
  101.             displayTotals();
  102.             break;
  103.         }
  104.         return continueGame;
  105.     }
  106.  
  107.     bool slotMachine::pullHandle(void) //local function defintions are illegal
  108. {
  109.         //checks to see if there is money
  110. //given by user then assigns a random value
  111. //to each wheel. Deducts the cost of one
  112. //pull from the users money.
  113.         double moneyInMachine = 100;
  114.         int wheelA = 1;
  115.         int wheelB = 2;
  116.         int wheelC = 3;
  117.  
  118.         moneyInMachine = moneyInMachine - moneyPaid;
  119.         cout << "You have \n" << moneyInMachine << endl;
  120.  
  121.         return true;
  122.  
  123.     }
  124.     void slotMachine::spinWheel(int &theWheel) //local function definitions are illegal
  125. {
  126.         //assign a random value to a wheel
  127.         int wheelA = 0;
  128.         int wheelB = 0;
  129.         int wheelC = 0;
  130.  
  131.         wheelA;
  132.         {
  133.             wheelA = 1 + rand() % (3 - 1 + 1);
  134.         }
  135.         wheelB;
  136.         {
  137.             wheelB = 1 + rand() % (3 - 1 + 1);
  138.         }
  139.         wheelC;
  140.         {
  141.             wheelC = 1 + rand() % (3 - 1 + 1);
  142.         }
  143.  
  144.  
  145.     }
  146.     double slotMachine::calculatePayout() // local function defintions are illegal
  147. {
  148.         //decides if the current wheel values merit a
  149. //payout and how much that payout should be.
  150. //deducts the total payout from the total
  151. //amount of money in the machine
  152.         int jackPot = 1000;
  153.         int goodJob = 10;
  154.         int youLose = -5;
  155.         int wheelA = 0;
  156.         int wheelB = 0;
  157.         int wheelC = 0;
  158.  
  159.         wheelA == wheelB && wheelA == wheelC;
  160.         {
  161.             cout << "Jackpot!!!" << jackPot << endl;
  162.         }
  163.  
  164.         wheelA == wheelB || wheelA == wheelC || wheelB == wheelC;
  165.         {
  166.             cout << "Good Job" << goodJob << endl;
  167.         }
  168.  
  169.         jackPot;
  170.         {
  171.             moneyInMachine = moneyInMachine + jackPot;
  172.         }
  173.  
  174.         goodJob;
  175.         {
  176.             moneyInMachine = moneyInMachine + goodJob;
  177.         }
  178.         return moneyInMachine;
  179.  
  180.     }
  181.     void slotMachine::insertCoin(double amount = 0.0)  //local function definitions are illegal
  182. {
  183.         //adds to the amount of money paid by the user
  184. //adds to the total money in the machine
  185.         int moneyInMachine = 100;
  186.         int moneyPaid = 0;
  187.  
  188.         moneyInMachine = moneyPaid + moneyInMachine;
  189.  
  190.  
  191.  
  192.     }
  193.     void slotMachine::displaySpinResults()
  194.     {
  195. //displays the value of the three wheels
  196.         int wheelA = 0;
  197.         int wheelB = 0;
  198.         int wheelC = 0;
  199.  
  200.         cout << "First wheel shows: \n" << wheelA << endl;
  201.         cout << "Second wheel shows: \n" << wheelB << endl;
  202.         cout << "Third wheel shows: \n" << wheelC << endl;
  203.  
  204.  
  205.     }
  206.     void slotMachine::displayTotals()
  207.     {
  208. //displays the total money in the machine and the number
  209. //of pulls the user has left
  210.         cout << "You have this much money left: $" << moneyInMachine << endl;
  211.         cout << "You have this many turns left: " << endl;
  212.  
  213.     }
  214.     int slotMachine::Random(int lowerLimit, int upperLimit)
  215.     {
  216. //returns a random number within the given boundary
  217.         return 1 + rand() % (upperLimit - lowerLimit + 1);
  218.     }
  219.  
  220. }
  221.  
And the errors:
Expand|Select|Wrap|Line Numbers
  1. code.cpp(107): error: member function "slotMachine::pullHandle" may not be redeclared outside its class
  2.       bool slotMachine::pullHandle(void) //local function defintions are illegal
  3.            ^
  4. code.cpp(108): error: expected a ";"
  5.   {
  6.   ^
  7. code.cpp(169): warning #12: parsing restarts here after previous syntax error
  8.           jackPot;
  9.                  ^
  10. code.cpp(171): error: identifier "jackPot" is undefined
  11.               moneyInMachine = moneyInMachine + jackPot;
  12.                                                 ^
  13. code.cpp(174): error: identifier "goodJob" is undefined
  14.           goodJob;
  15.           ^
  16. code.cpp(181): remark #869: parameter "amount" was never referenced
  17.       void slotMachine::insertCoin(double amount = 0.0)  //local function definitions are illegal
  18.                                           ^
  19. code.cpp(220): error: expected a declaration
  20.   }
  21.   ^
  22. compilation aborted for code.cpp (code 2)
  23.  
EDIT: It will take me a while to fix all the problems. With the formatted source code, it should be easy to see that the issue is a missing brace for displayMenu. So add a closing brace before pullHandle.
Oct 7 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

1
4085
by: Chris Cranford | last post by:
I am in the process of implementing a stack machine virtual environment where each entry on the stack is a 32-bit value which then can reference to any memory pointer, numeric value, or alike. My understanding of "stack" versus "heap" is that unless I use new/delete in order to specifically allocate memory for a variable's storage space that it will be allocated upon the stack, correct? If so, the following three declarations would...
1
5034
by: MingChih Tsai | last post by:
Hi there, Are there any slot machine c# sample codes for reference ? Thanks !! Best regards, Paul
1
1984
by: shane.tietjen | last post by:
If you are dealing with one PCI card, is there a way (from within a dll) to find out which PCI slot that card is inhabiting (1 or 2 or 6, etc.)? It doesn't matter if the solution is MFC, or straight C++/C, just has to be on a Windows machine. Thanks in advance.
10
2555
by: stwebmail | last post by:
If you are dealing with one PCI card, is there a way (from within a dll) to find out which PCI slot that card is inhabiting (1 or 2 or 6, etc.)? It doesn't matter if the solution is MFC, or straight C++/C, just has to be on a Windows machine.
1
2528
by: Fred B | last post by:
I am launching a new thread from my application's main process (using VB.net 2003), and I can't get the child to receive the parameter I'm attempting to send it in a named data slot. The code for launching the thread: Dim NewThread As New Thread(AddressOf LaunchCommThread) NewThread.AllocateNamedDataSlot("Offset") NewThread.IsBackground = True NewThread.Name = SIMclass.SIM(1).strCtrlDesignator
1
5692
by: peterggmss | last post by:
This is a slot machine game, 2 forms. One is the actual game (frmMachine) and the other is in the background and randomizes the images shown on frmMachine. I need to make frmMachine wait for frmRandom, i tried it with the Sleep API and a Do/Until Loop and neither worked, could you please help me, I have my code below. frmMachine 'Slot Machine, (c) 2006 Peter Browne, GPL Licensed ' 'Peter Browne 'Sheridan Corporate Centre '2155 Leanne...
1
3198
by: raishi | last post by:
I am trying to figure out how to make a simple slot machine program in VBScript that starts by prompting and collecting the desired number of slot machine spins to simulate simulates the spins: each spin requires a randomly generated three picture enum values each of those values is printed to the screen as Lion, Cherry, Bar, Lemon or Lime The result of the spin is then printed, jackpot, winner, or loser Jackpot = all values are the same...
4
2119
by: Tracid83 | last post by:
hi, I use wmi to get slot information from remote computer.I want to know the name of the device connected on the specific slot. Thanks for your help Tracid
2
1942
by: Carnell, James E | last post by:
I am thinking about purchasing a book, but wanted to make sure I could get through the code that implements what the book is about (Artificial Intelligence a Modern Approach). Anyway, I'm not a very good programmer and OOP is still sinking in, so please don't answer my questions like I really know anything. MY QUESTION: What is a slot? In class Object below the __init__ has a slot. Note: The slot makes use of a data object called...
0
9715
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10603
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10353
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10356
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10099
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9176
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7643
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5675
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3836
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.