The two characters (one, two) have the same values generated.
How can I make them have different numbers generated?
Currently, the out put is:
"The character has 2 eyes, an age of 66, and 8 legs.
The character has 2 eyes, an age of 66, and 8 legs."
I want each character to have unique stats, unless by some amazing chance ;)
#include<iostream>
#include<conio.h>
#include<ctime>
using namespace std;
struct Char
{
int eyes;
int legs;
int age;
public:
void setEyes(int eyes);
void setLegs(int legs);
void setAge(int age);
};
void Char::setEyes(int eyes)
{
Char:: eyes= eyes;
}
void Char::setLegs(int legs)
{
Char:: legs= legs;
}
void Char::setAge(int age)
{
Char:: age= age;
}
void displayChar(Char whatever)
{
cout<<"The character has "<<whatever.eyes<<" eyes, an age of "<<whatever.age<<", and " <<whatever.legs<<" legs."<<endl;
}
int main ()
{
Char one;
const int DIVISORage= 100;
const int NUM = 1;
int x;
srand((unsigned)time(NULL));
for (x=0;x<NUM;++x)
{
one.age=rand() % DIVISORage;
}
const int DIVISORlegs= 12;
int y;
srand((unsigned)time(NULL));
for (x=0;x<NUM;++x)
{
one.legs=rand() % DIVISORlegs;
}
const int DIVISOReyes= 10;
int z;
int eyes;
srand((unsigned)time(NULL));
for (x=0;x<NUM;++x)
{
one.eyes=rand() % DIVISOReyes;
}
displayChar(one);
Char two;
const int DIVISORage2= 100;
srand((unsigned)time(NULL));
for (x=0;x<NUM;++x)
{
two.age=rand() % DIVISORage2;
}
const int DIVISORlegs2= 12;
srand((unsigned)time(NULL));
for (x=0;x<NUM;++x)
{
two.legs=rand() % DIVISORlegs2;
}
const int DIVISOReyes2= 10;
srand((unsigned)time(NULL));
for (x=0;x<NUM;++x)
{
two.eyes=rand() % DIVISOReyes2;
}
displayChar(two);
getch();
}
Thanks in advance! :)