Hello. I'm trying to read the data from C:\Random.txt
I've included the fstream but the compiler gets hung up at the inputFile.open line. I read in my book to use two backslashes. I tried to locate the Random.txt file in a basic location so the location address wouldn't be too long or complicated.
/*CSC 134 80 Module 5 Week 2
Peer Programming Assignment
Josh Krynock 3/27/16
This program will read a list of numbers from Random.txt file
and then calculate and display the following iformation:
1- The count of numbers in the file.
2- The sum of all the numbers in the file (a running total)
3- The average of all the numbers in the file.
*/
#include <iostream>
#include <iomanip>
#include <fstream>
usingnamespace std;
int main()
{
//statement for reading a file
ifstream inputFile;
//Open the file
inputFile.open(c:\\Random.txt)
//Variables
int numCount = 0;
double aveNumbers, number, numTotal = 0;
if (inputFile) //To test file open errors.
{
cout << "This program reads a list of numbers from a file\n";
cout << "and the displays the number of numbers in the file,\n";
cout << "the sum and the average of all the numbers in the file.\n";
cout << "Reading file...\n\n";
while (inputFile >> number)
{
cout << number << endl;
numCount++;
numTotal += number;
}
aveNumbers = (numTotal / numCount);
cout << "Sum of numbers: " << numTotal << endl;
cout << "Average of numbers: " << aveNumbers << endl;
}
else
cout << "File load error.";
return 0;
}