The program is to generate random numbers to a file and will have one integer parameter, Open a file and then using a loop write the required number of random numbers to the file. Scale the random numbers from 1 and 100 inclusive. Then closes the file .The last function will read the numbers in the file into your program.
so far i have
Code:
#include <iostream>
#include <string>
#include <iomanip>
#include <ctime>
#include <fstream>
#include <cstdlib>
using namespace std;
int Validate();
int main()
{
int t;int random;
ifstream inputFile;
t = Validate();
int random_integer;
inputFile.open("Randoms.txt");
//How do you make it put the random numbers in a file after asking the user to determine how many to put.
srand((unsigned)time(0));
for(int index=0; t; index++);
random = (rand()%1000)+1;
cout << random << endl;
int index;
ifstream ifile("Randoms.txt");
if(ifile)
{
for(index = 0;index > 0; random++)
ifile >> random;
ifile.close();
}
else
{
cout << "Error, file failed to open\n";
system("pause");
exit(2);
}
system("pause");
return 0;
}
int Validate()
{
int t;
do
{
cout << "How many numbers to write?"<< endl;
cin >> t;
}
while (t <50 || t >1000);
return (t);
}