Starting a Program

Write your question here.

Probably a very basic question, but I don't know how to fix it
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
#include <iomanip>
#include <cstdlib>

using namespace std;

#define minimum_value 2
#define maximum_value 10


int main ()
{
	
	int times;
	times = minimum_value + (rand() % (maximum_value - minimum_value + 1));
	cout << "This program will generate " << times << " numbers.";
	
	
	
return 0;
	}


I'm looking to generate a number between 2-10, but it always comes out 7 because I believe it to just be assigning 7 to it each time with "int times;".

However, if i don't declare "times" it won't run.

Any help would be appreciated.
this is probably correct.
The first number from random is always the same if you always use the same seed.

you didn't seed it, so it might be doing just that.

you needs a srand (time(NULL)); before rand() is called.

Topic archived. No new replies allowed.