Erm, sorry but you're not very clear about your question.
Is the function a function you made yourself, or is it "rand()"?
The problem is that I need to call the function several times during the program, each with an individual result
I don't see the problem here... each time you get a random number, it gives you a different random number. Otherwise it wouldn't be very random...
(randomly generated doubles are acceptable, though)
Wha??? Isn't that the same thing??
The function is caleld up to 20 times, and i don't want to create 20 different variables within my main
Hmm, I think there's a misunderstanding... you can reuse variables.
Code:
#include <time.h>
#include <iostream>
int main()
{
srand(time(NULL));
//Create 2 variables to hold the random numbers
int randomNumber1, randomNumber2;
for(int i = 0; i < 20; ++i) //Loop 20 times
{
randomNumber1 = (rand() % 6) + 1;
randomNumber2 = (rand() % 6) + 1;
if(randomNumber1 == randomNumber2)
std::cout << "Equal." << std::endl;
else
std::cout << "Not equal." << std::endl;
}
return 0;
}
I'm not 100% sure if the srand() line will work, I'm used to using GetTickCount() instead of time(NULL) since I do more Windows programs, but other than that line, the code should generate 20 pairs of random numbers and compare them for equality then quit.
**EDIT** In case you meant you need to generate 20 random numbers and store ALL of them, then if you don't know how to use arrays, I suggest you learn to. In fact, I suggest you learn to use them regardless