// Variables
int count = 0; // To count numbers
int count1 = 0;
double number; // To hold a number from the file
double total = 0.0; // Accumulator
double average; // To hold the average
char words;
double words1;
// File stream object
ifstream inFile;
// Open the file.
inFile.open("C:\\Users\\User\\Desktop\\programming110\\random.txt");
// check if the file is open
if (!"C:\\Users\\User\\Desktop\\programming110\\random.txt")
{
cout << "File open failure.";
}
while (inFile >> number)
{
// We have a number! Increment the counter.
count++;
// Add the number to the accumulator.
total += number;
}
while (inFile >> words)
{
count1++
words1 += words;
}
// Close the file.
inFile.close();
// Calculate the average of the numbers.
average = total / count;
// Display the results.
cout << "Number of numbers: " << count << endl
<< "Sum of the numbers: " << total << endl
<< "Average of the numbers: " << average
<< endl;
<< "Number of words: " << count1 << endl;
return 0;
}