So in this code, I'm trying to append the smallest number in an array into the file. But whenever I do, It appends 0 and not the smallest number. I had read the numbers into the array from a file, and trying to append the smallest number.
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
int pcount = 0;
ifstream inFile;
inFile.open("numbers.txt");
int i;
int myArray[i];
while (!inFile.eof()) {
inFile >> myArray[i];
pcount++;
}
inFile.close();
cout << pcount << endl;
int temp = myArray[0];
for (int i = 0; i < pcount; i++) {
if (temp > myArray[i]) {
temp = myArray[i];
}
}
inFile.close();
ofstream outFile;
outFile.open("numbers.txt");
cout << "Appended lowest integer into file." << endl;
outFile << temp;
}