I'm using rand() function in C++. I Have created the following code:
#include <cstdlib>
#include <iostream>
#include <ctime>
using namespace std;
/*
*
*/
void proccessTZ(int t, int z) {
if (t > z) {
cout << "t > z" << endl;
} else if (t < z) {
cout << "t < z" << endl;
} else {
cout << "error" << endl;
}
}
int makeTZ() {
srand((unsigned)time(0));
int a = (rand() % 10) + 1;
cout << a << endl;
return a;
}
int main() {
int t = makeTZ();
int z = makeTZ();
proccessTZ(t,z);
return 0;
}
I wrote the makeTZ() method and call it twice in my main method but it always gives me a random number thats the same for t and z. E.g t = 4 and z = 4 or t = 6 and z = 6 or t = 10 and z = 10. Why is it doing this?

New Topic/Question
Reply




MultiQuote







|