Working on an exercise and I think I'm pretty close to getting it right. The prompt asks for me to have the user say how many random numbers they want generated, and then to generate that many random numbers. For simplicity I'm having the random numbers be 0-1000. We're practicing using files too, so we want this written to a file.
#include <iostream>
#include <fstream>
#include <ctime>
int main()
{
int userinput,i, N, rdnum[N];
std::ofstream ofs;
std::cout << "How many random numbers do you want to generate?\n";
std::cin >> N;
srand(time(0));
rdnum[N] = rand() % 1001;
ofs.open("rand_numbers.txt");
if (!ofs)
{
std::cout << "Open error\n";
exit(0);
}
else if (ofs.good())
{
for (i = 0; i < N; i++)
{
std::cout << "Random numbers: " << rdnum[i] << std::endl;
ofs << rdnum[i] << std::endl;
}
}
}
Thanks!