Hi again, sorry to keep posting questions in this forum but i have nowhere else to find answers . I'm now trying to make a simulation of a slot machine but for some reason which i should probably already know the slot machine will always have the same three results.
I am using the time function for randomness which i think is the problem as the three results are calculated at pretty much the same time although i do not know how to fix this.
Here is the code the my unfinished program:
Code:
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>
using namespace std;
int money = 1000;
int bet;
void slotResult()
{
int counter = 0;
while (counter < 3)
{
srand (time(NULL));
int i = rand() % (3 - 1 + 1) + 1;
switch (i)
{
case 1:
{
cout <<"BALL\t";
break;
}
case 2:
{
cout <<"COIN\t";
break;
}
case 3:
{
cout <<"STICK\t";
break;
}
}
counter++;
}
}
int main ()
{
cout <<"YOU HAVE $1000 TO SPEND ON THE SLOT MACHINE";
cout <<"\n\n";
cout <<"INSTRUCTIONS: PLACE A BET, IF YOU GET 3 MATCHING ITEMS YOU RECIEVE QUADRUPLE THE \nAMOUNT WHICH YOU BET, IF YOU DO NOT YOU LOSE YOUR BET";
cout <<"\n\n\n\n";
cout <<"ENTER BET: ";
cin >>bet;
slotResult();
}
Can someone please tell me what i am doing wrong here?
thanks in advance