Slot Machine Project

Hello, I'm having issues with my slot machine game. I'm required to keep score on the amount of points the player receives, but I don't really know how to go about that.

I thought about creating another function with an "if/else" statement using the position of the objects so I would keep score of the game, but so far it's been unsuccessful. Can you guide me on what I should do? Please be detailed.

Note: I am using a Windows environment. Also, disregard "Game Stats" or "Exit". I have yet to create a function for it.

Thank you!

Code -

#include <iostream>
#include <Windows.h>
#include <string>
#include <iomanip>
#include <ctime>


using namespace std;

enum Options { TOMATO, ORANGE, APPLE, PINEAPPLE, STRAWBERRY, GRAPES };

const int MILIDELAY = 100;
const int NUMSPINS = 50;

string outputOptions(Options x);
void getPos(Options& x);
void delay();
void spinMachine(Options& one, Options& two, Options& three);
void getStopOrder(int& first, int& second, int& last);
void countScores(Options& posOne, Options& posTwo, Options& posThree);

int main()
{
Options posOne = TOMATO;
Options posTwo = TOMATO;
Options posThree = TOMATO;
char userChoice = 'z';

int points = 0;
int action;

cout << setw(100) << "CUBE ENTERTAINMENT";
cout << "\n\n1. Play SLOT Machine"
<< "\n2. Game Stats"
<< "\n3. Exit";

cout << "\n\nResponse - ";
cin >> action;

switch (action)
{
case 1:
system("cls");
cout << setw(100) << "SLOT MACHINE" << "\n\n";
Sleep(2000);

while (userChoice != 'n')
{
spinMachine(posOne, posTwo, posThree);
cout << "\nWould you like to spin again? (y/n): ";
cin >> userChoice;
cout << "\n";

}
break;


case 2:
cout << "\nGame Stats";
break;

case 3:
cout << "\nExit";
break;

default:
cout << "\nInvalid Solution";
}

return 0;
}
//create your functions here







string outputOptions(Options x)
{
switch (x)
{
case TOMATO:
return "TOMATO";
break;
case ORANGE:
return "ORANGE";
break;
case APPLE:
return "APPLE";
break;
case PINEAPPLE:
return "PINEAPPLE";
break;
case STRAWBERRY:
return "STRAWBERRY";
break;
case GRAPES:
return "GRAPES";
break;

}
}

void getPos(Options& x)
{
if (x == GRAPES)
x = TOMATO;
else
x = static_cast<Options>(x + 1);

}
void delay()
{
clock_t endWait = clock() + MILIDELAY;
while (clock() < endWait)
{

}

}
void spinMachine(Options& posOne, Options& posTwo, Options& posThree)
{
int first, second, last;
int count = 0;

int numStopFirst = 20, numStopSecond = 10;

while (count <= NUMSPINS)
{
getStopOrder(first, second, last);

if (first == 1)
{
if (count <= NUMSPINS - numStopFirst)
{
getPos(posOne);
}
if (second == 2)
{
if (count <= NUMSPINS - numStopSecond)
getPos(posTwo);
getPos(posThree);
}
else
{
if (count <= NUMSPINS - numStopSecond)
getPos(posThree);
getPos(posTwo);
}
}
else if (first == 2)
{
if (count <= NUMSPINS - numStopFirst)
{
getPos(posTwo);
}
if (second == 3)
{
if (count <= NUMSPINS - numStopSecond)
getPos(posThree);
getPos(posOne);
}
else
{
if (count <= NUMSPINS - numStopSecond)
getPos(posOne);
getPos(posThree);
}
}
else
{
if (count <= NUMSPINS - numStopFirst)
{
getPos(posThree);
}
if (second == 2)
{
if (count <= NUMSPINS - numStopSecond)
getPos(posTwo);
getPos(posOne);
}
else
{
if (count <= NUMSPINS - numStopSecond)
getPos(posOne);
getPos(posTwo);
}
}

delay();
cout << "Spinning: " << setw(15) << outputOptions(posOne) << setw(15) << outputOptions(posTwo) << setw(15) << outputOptions(posThree) << "\r";
count++;
}
}

void getStopOrder(int& first, int& second, int& last)
{
srand(time(0));
first = rand() % 3 + 1;
last = rand() % 3 + 1;
if (first == last)
{
if (last == 3)
{
last = 1;
second = 2;
}
else
{
last = last + 1;
if (last == 3)
second = 1;
else
second = last + 1;
}
}
else if (first == 1)
{
if (last == 2)
second = 3;
else
second = 2;
}
else if (first == 2)
{
if (last == 3)
second = 1;
else
second = 2;
}
else
{
if (last == 1)
second = 2;
else
second = 1;
}
}

Last edited on
"I'm required" would probably indicate this is a homework assignment... After all if you had actually written this code it would have been very easy to make such thing.

Your problem can be solved with only 3 lines of code.

void countScores(Options& posOne, Options& posTwo, Options& posThree)
{
int scores[6] = {10, 20, 30, 40, 50, 60}; // score order equal to options enum

if (all options are equal)
playerScore += item from scoresarray equal to options enum;
}

This however if you study the code should get you on your way.
Topic archived. No new replies allowed.