I'm building a program in which a user types in a number (n) and a set of random numbers is created. So for example, if a user inputs 8, then eight random numbers should be created and they should range from 0-999,999. The program seems to be compiling, the only problem is, only one random number is being generated.
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
main()
{
int n;
int r;
int i;
int j;
vector<int> v;
cout << "Enter size of vector: ";
cin >> n;
for (i = 0; i < n; i++)
{
v.push_back(n);
r = rand() % 1000000;
v[i] = r;
}
cout << r << endl;
Can anyone tell me what I'm doing wrong and what I need to do for more than one random number to be generated?