Random number problem....Its not random
Jan 27, 2012 at 12:12pm UTC
What am I doing wrong!
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 51 52 53 54
#include<iostream>
#include<vector>
#include <cstdlib>
#include <ctime>
#include<windows.h>
using namespace std;
class Chairs
{
private :
bool ch;
public :
Chairs()
{
ch = false ;
}
Chairs(bool b)
{
ch = b;
}
};
class Shop
{
private :
vector<Chairs> c;
public :
Shop()
{
Chairs obj1(false );
Chairs obj2(false );
Chairs obj3(false );
c.push_back(obj1);
c.push_back(obj2);
c.push_back(obj3);
}
void setStatus()
{
int random; //declaring for random number
srand(time(NULL)); //getting system time
random = random% 4;
cout << random;
}
};
int main()
{
Shop BarbarShop;
for (int i =0 ; ; )
{
BarbarShop.setStatus();
Sleep(30);
}
return 0;
}
Jan 27, 2012 at 12:16pm UTC
Solved it
1 2 3 4 5 6 7 8
void setStatus()
{
int random; //declaring for random number
srand(time(NULL)); //getting system time
random = rand();
random = random% 4;
cout << random;
}
Topic archived. No new replies allowed.