Return various values for different executions

Hi everybody,

I need help to code the following program :
This program have to return different values when it executes. For instance :
Return Value
- 1st execution : 1
- 2st execution : 3
- 3rd execution : 5
....

Please help me to solve this issue. Best weekend :)
The program has to store data somewhere. In a file.
Are there any solutions without utilizing a file ? @keskiverto
use random values ?
I second that anup30.

Use the srand() and rand() which is under the cstdlib library.

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include <cstdlib>

int main()
{
	srand (time(0));
	int number = rand() % 100 + 1; // generate random number between 1 and 100
                                       // then assign it to the integer variable number.
	std::cout << number;
	
	std::cin.get();
	return 0;
}


Happy coding...
Topic archived. No new replies allowed.