random number generator

Hi everyone, so I'm writing a code for class that requires me to create two input files that reads in 50 numbers each from a random number generator and output into one input file. The problem I am having is that I cannot get the random numbers to print to my input file, but it works for the output file. So far in my code I onl have one input file but that's okay because if I can get one I can get the other.
This is my code: (sorry i dont know how to use the codes braces, if Icould get help with that too that would be fantastic)

#include <iostream>
#include <cstdlib>
#include <fstream>
#include <ctime>
using namespace std;

int main()
{
ifstream fin;
ofstream fout;
srand(time(NULL));
fin.open("input1.txt");
fout.open("output1.txt");

for (int i = 0; i < 50; i++)
{
fout << 1 + (rand() % 100) << endl;
}


fin.close();
fout.close();
system("pause");
return 0;
}
What the problem with code you posted? It works fine for me.

I cannot get the random numbers to print to my input file
Input streams are for reading, you cannot write anything to it.
Yeah on some level I knew that but in classed my teacher talked of a way to leave the input file blank and after doing some code, the random number would appear in it
Topic archived. No new replies allowed.