[HELP]Simple Roulette program

If I run this roulette code (it is inspired by that csgo500 site) on phone, everything works fine, but if i do try it at PC , the maximum generated number is somewhere after 30000, prob the 32768(idk for sure). Why is it working on phone, and why isn't it working on computer?

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
//Chances for every of the colors to be drawn:
//1.851 - gold
//48.148 - black
//31.481 - red
//18.518 - blue
#include <iostream>
#include<ctime>
#include<cstdlib>
using namespace std;
int main()
{
unsigned k,k2,k3,k4;
k=0;
k2=0;
k3=0;
k4=0;
srand((unsigned)time (0));
cout<<"      CSGO500    \n\n  ";
cout <<"\nHow many times shall the program run?"<<endl;
int n;
cin>>n;
while (n<1)
    {
    cout <<"Wrong answer"<<endl;
        cin>>n;
}
int i;
float x;
for(i=1;i<n;i++)
{
x=1000+rand()%99000; //Generating a float number with 3 decimals by generating a number between 1000 and 100000 then dividing it by 1000(x is a float value variable)
x=x/1000;
if (x<=1.851) {cout <<"GOLD"<<endl;
   k=k+1;     }
else if (x>=51.852) {cout <<"BLACK"<<endl;  k2=k2+1;   }
else if (x<=33.332&&x>1.851){ cout <<"RED"<<endl; k3=k3+1;}
else {cout <<"BLUE"<<endl;k4=k4+1; }

}
 cout <<"\n\nIn total, there were generated "<<k2<<" x BLACK, "<<k3 <<" x RED , "<<k4<<" x BLUE and "<<k<<" x GOLD"<<endl;
cin.get ();
    cin.get ();
    return 0;

}
Last edited on
Up
Try displaying RAND_MAX.
 
  cout << "RAND_MAX=" << RAND_MAX << endl;


On my 32 bit system, RAND_MAX is 32767. That means x is going to be between 1 and 33.767 and you will never see BLACK or BLUE.

Last edited on
Topic archived. No new replies allowed.