?
2019-11-14 05:02:08 UTC
#include
#include
using namespace std;
int main()
{
const int ARRAY_SIZE = 12; // Array size.
int numbers[ARRAY_SIZE]; // Array with 12 elements.
int count = 0; // Loop counter variable.
string filename; // For the user to enter the file name.
ifstream inputFile; // Input the file stream object.
// Get the file name from the user.
cout << "Enter the name of the file you wish to open : ";
cin >> filename;
inputFile.open(filename); // Open the file.
if (inputFile)
{
while (count < ARRAY_SIZE && inputFile >> numbers[count])
{
count++;
}
// Close the file.
inputFile.close();
}
Okay so I have this code written, and alot more after that which all runs fine, but I keep getting an error in the area where im trying to open the file,
for the line " inputFile.open(filename)
I am not sure why I keep getting an error considering 1) I have the file needed saved in the same folder as my project and I even linked it/compiled it
and 2) i cross referenced my code with a ton of sites on google and everyone says this is how to do it.
USEFUL INFO: The prompt I had was to take a "user inputted file" which you want to be the one that you already have saved, and calculate the average total and sum of the numbers listed in the file, what pisses me off is the "user input" part because why can't I just use the file provided? anyway thanks!