What I'm trying to do is basically this, I want a certain rand function to be usable multiple times. For example:
Srand(time(0));
int x = rand()%100;
int z = 50;
while ( z == 50 )
cout<<" The Number is "<<x;
cout<<z-x;
break;
}
So here I want it to display the random number first, and then re-use it as z(50) - x(rand()%100). But what it does is make 2 completely different numbers.
How can I make a rand number and then use the same number again to subtract from a variable?
Class X {
private:
int z;
public:
z():
z(100);
{
}
void setValue( int x ) {
z = x ;
}
int getValue() {
return x;
}
};
X char;
srand (time(NULL));
int e = rand()%100
while ( char.getValue() >1 ) {
cout<< " the random number is: "<<e;
char.setValue(100-e);
}
Now, the char.setValue(100-e); will keep subtracting from a random number. but I want it to keep it's last subtraction. For example if the number is 50, the char.setValue should now hold only 50 instead of the 100 I declared at the start.
I know my question is difficult, but bear with me please.
Your question is not difficult.
But the code you posted above does not compile. How about just sharing the actual code which you are running and which gives you a problem.