Slot machine help
Aug 16, 2012 at 4:21pm UTC
Im making a slot machine and im trying to make it so it picks random symbols but it just keeps picking the @ symbol all the time, why is that?
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
#include <iostream>
#include <string>
#include <ctime>
#include <random>
using namespace std;
int main()
{
int spin;
int TIME;
char result1;
char result2;
char result3;
char result4;
char result5;
char a = '@' ;
char b = '$' ;
char c = '*' ;
char d = '#' ;
char e = '&' ;
time_t T;
ctime(&T);
srand(T);
TIME = rand() % 5;
cout << "Enter 's' to spin\n" << endl;
switch (TIME)
{
case 0:
result1 = a;
break ;
case 1:
result2 = b;
break ;
case 2:
result3 = c;
break ;
}
cout << result1 << endl;
cout << result2 << endl;
cout << result3 << endl;
}
Aug 16, 2012 at 4:35pm UTC
If you're going to use the time as your random seed, you need to actually get the time, using the
time function.
Last edited on Aug 16, 2012 at 4:35pm UTC
Aug 16, 2012 at 4:46pm UTC
Additionally, only use srand (time(NULL));
once per execution of the code. I.E. place it as the first line in int main. this will prevent duplicate results.
Topic archived. No new replies allowed.