I have to write a slot machine program where theres 3 wheels.
wheel 1 = cherry, cherry, cherry, plum, plum, bell, bar
wheel 2 = cherry, cherry, plum, plum plum, bell, bar
wheel 3 = plum, plum, bell, bar, cherry cherry.
when wheels "spin", output should show three items from each wheel (each wheel is a column of output).
player can put in 1 -3 coins, and 0 to exit
when 1 coin is enetered, middle row is evaluated; 2 coins, top two rows; 3 coins, all rows.
can anyone help me with this? this is what I have so far:
#include <iostream>
#include <cstdlib> //for rand & srand functions
#include <ctime> //for time function
#include <cassert> //for assert function
using namespace std;
void spin(int wheel[], int wheelsize, int column, int position[][3], int positionsize);
void NumConversion(int);
int evalpayout(int A[][], int B[][], int C[][]);
int main ()
{
char exitkey;
int total = 5, coinsin, coinswon = 0, winnings;
int wheel1[7] = {1, 1, 1, 2, 2, 3, 3}, wheel2[7] = {1, 1, 2, 2, 2, 3, 4}, wheel3[7] = {2, 2, 3, 3, 4, 1, 1};
int spin_result[3][3];
cout << "How many coins would you like to insert?";
cout << "You can play up to 3 coins. Enter 0 to exit." << endl;
cin >> coinsin;
assert ( coinsin >= 0 && coinsin <= 3); //program terminates if invalid number of coins played is entered
do
{
total = total - coinsin;
spin(wheel1, 7, 0, spin_result, 3); //generates numerical spin results for each wheel
spin(wheel2, 7, 1, spin_result, 3);
spin(wheel3, 7, 2, spin_result, 3);
cout << "The wheels spin. The show the following: "<<endl;
cout << endl;
for(int i = 0; i < 3; i++) //outputs spin results
{
for (int j = 0; j < 3; j++)
NumConversion(spin_result[i][j]); //converts the numerical spin results to word results
cout << endl;
}
if(coinsin == 1)
{
evalpayout(spin_result[1][0], spin_result[1][1], spin_result[1][2]); //evaluates middle row
coinswon = winnings;
}
else if (coinsin == 2)
{
evalpayout(spin_result[0][0], spin_result[0][1], spin_result[0][2]); //evaluations first row
coinswon = winnings;
evalpayout(spin_result[1][0], spin_result[1][1], spin_result[1][2]); //evaluations middle row
coinswon = winnings; //adds first row winnings to middle row winnings for total coins won
}
else
{
evalpayout(spin_result[0][0], spin_result[0][1], spin_result[0][2]); //evaluations first row
coinswon = winnings;
evalpayout(spin_result[1][0], spin_result[1][1], spin_result[1][2]); //evaluations middle row
coinswon = winnings; //adds first row winnings to middle row winnings
evalpayout(spin_result[2][0], spin_result[2][1], spin_result[2][2]); //evaluations last row
coinswon = winnings; // adds last row winnings to middle + first row winnings for total coins won
}
cout << endl;
cout << "You win " << coinswon << " coin(s)." << endl;
cout << endl;
total = total + coinswon;
cout<<"How many coins would you like to insert?";
cin >> coinsin;
assert ( coinsin >=0 && coinsin <=3);
} while (coinsin != 0);
cout<<endl;
cout<<"Your final balance is " << total <<" coins."<<endl;
cout << endl;
cout << "Press any key then <enter> to exit: ";
cin >> exitkey;
cout << "Good Bye!";
return 0;
}
void spin(int wheel[], int wheelsize, int column, int position[][3], int positionsize)
{
int next = 0;
srand(time(0)); //seed random number generator with system time
next = rand() % 6;
for(int index =0; index < positionsize; index++)
{
position[index][column] = wheel[next];
if ((next + 1) > (wheelsize - 1))
next = 0;
else
next = next + 1;
}
}
void NumConversion(int x) //converts all the random nubers generated into word outputs.
{
switch(x)
{
case 0:
cout << setw(8) << "Cherry";
break;
case 1:
cout << setw(8) << "Plum";
break;
case 2:
cout << setw(8) << "Bell";
break;
case 3:
cout << setw(8) << "Bar";
break;
}
}
int evalpayout( int A[][], int B[][], int C[][]) //takes in a specific row to evaluate payout
{
int winnings = 0;
if(A[x][0] = 2 && B[x][1] = 2 && C[x][2] = 2)
winnings = winnings + 6;
if(A[x][0] = 3 && B[x][1] = 3 && C[x][2] = 3)
winnings = winnings + 9;
if(A[x][0] = 4 && B[x][1] = 4 && C[x][2] = 4)
winnings = winnings + 30;
if(A[x][0] = 2 && B[x][1] = 2)
winnings = winnings + 4;
if(A[x][0] = 3 && B[x][1] = 3)
winnings = winnings + 6;
if(A[x][0] = 4 && B[x][1] = 4)
winnings = winnings + 10;
if (A[x][0] = 2)
winnings = winnings + 2;
if (A[x][0] = 3)
winnings = winnings + 3;
if (A[x][0] = 4)
winnings = winnings + 5;
return winnings; //returns winnings to use towards calculating total coins won.
}