Hello, I am making a program that simulates a slot machine. I think I have the idea right, but I am getting errors mainly on my function prototypes.
I have it divided into 3 files.
Main .cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
|
/*******************************************
.
.
.
.
Main Algorithim:
#include..
namespace..
Class
Public
Constuctor
Initilize 12 coins
# OF COIN Function
Get number of coins left in machine
PLAY Function
Insert coin, random number of winning/losing
Private
Function
Add a coin from user
Function
Get Random Number
Pay out coin if, win/loose
int main
Initilize # of coins in the machine
while coin is > than 0
Call PLAY function
{ INSIDE THE FUCNTION
Ask user to enter one coin to play y/n
IF y, continue
IF n, display coins won, quit
CALL ADD A COIN FUNCTION
CALL RANDOM FUNCTION
If int returned is >=1 && <=7 then the player wins one coin
Return true/false
}
if bool == true
minus a coin from the machine
tell user he won
end main
FUNCTIONS
********************************************/
#include <iostream>
#include "A3BJ.h"
#include <iomanip>
using namespace std;
int main()
{
srand(time(0)); //Seeds random number generator
slotmachine sm;
int randomNumber =0;
int numOfCoins =0;
bool winLose = false;
char yesNo;
while(numOfCoins > 0)
{
cout << "Enter one coin to play? y/n" << endl;
cin >> yesNo;
while( yesNo == 'y' || yesNo == 'Y')
{
winLose = slotmachine::play(numOfCoins, randomNumber);
}
if(winLose == true)
{
numOfCoins = numOfCoins - 1;
cout << "You've won one coin" << endl;
}
else
{
cout << "You lost one coin" << endl;
}
}
cout << "You've won all of the coins in the machine!" << endl;
return 0;
}
// End Main
|
ERROR:"A3BJ.cpp", line 80: Error: Use "." or "->" to call slotmachine::play(int, int).
Class .cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
#include "A3BJ.h"
#include <iostream>
#include <iomanip>
slotmachine::slotmachine();
{
numOfCoins = 12;
randomNumber = 0;
}
bool slotmachine::play(int numOfCoins, int randomNumber);
{
numOfCoins = addCoin();
randomNumber = ranNum();
if(randomNumber >= 1 && randomNumber <=7)
{
return true;
}
else
{
return false;
}
}
int slotmachine::addCoin()
{
numOfCoins = numOfCoins + 1;
return numOfCoins;
}
int slotmachine::ranNum()
{
int randomNum = rand()%10+1;
return randomNum;
}
|
ERRORS:
"A3BJfunc.cpp", line 6: Error: The class member slotmachine() cannot be declared outside the class.
"A3BJfunc.cpp", line 7: Error: A declaration was expected instead of "{".
"A3BJfunc.cpp", line 10: Error: A declaration was expected instead of "}".
"A3BJfunc.cpp", line 13: Error: The class member play(int, int) cannot be declared outside the class.
"A3BJfunc.cpp", line 14: Error: A declaration was expected instead of "{".
"A3BJfunc.cpp", line 15: Error: Multiple declaration for numOfCoins.
"A3BJfunc.cpp", line 15: Error: The function "addCoin" must have a prototype.
"A3BJfunc.cpp", line 16: Error: Multiple declaration for randomNumber.
"A3BJfunc.cpp", line 16: Error: The function "ranNum" must have a prototype.
"A3BJfunc.cpp", line 18: Error: A declaration was expected instead of "if".
"A3BJfunc.cpp", line 18: Error: ")" expected instead of ">=".
11 Error(s) detected.
header.h
//Contains Class and function prototypes
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
#include <iostream>
#include <iomanip>
using namespace std;
class slotmachine
{
public:
slotmachine();
int numCoin(int numOfCoins); //Number of coins in the machine
bool play(int numOfCoins, int randomNumber);
private:
int addCoin(); //Adds coins to the machine
int ranNum(); //Finds random Number
};
|