So my program is supposed to generate 30 random numbers, put them in a file, then save those numbers in an array, but when I try to print out the numbers in a file they are not the numbers that are in the file but instead are some random huge numbers.
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <fstream>
using namespace std;
void sortFile() {
fstream f;
int numbers[30];
int n;
f.open("f.txt");
srand(time(NULL));
for(int i; i < 30; i++) {
f << rand() % 30 + (-9) << endl;
}
while(!f.eof()) {
f >> numbers[n];
n++;
}
f.close();
for(int i; i<30;i++) {
cout << numbers[i] << endl;
}
}
int main() {
sortFile();
}