I saved the file \"test.txt\" in the following format in the same directory as t
ID: 3644677 • Letter: I
Question
I saved the file "test.txt" in the following format in the same directory as the program1.3
2.3
1.2
3.45
6.78
2.34
The modified program is:
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream inputfile;
inputfile.open("test.txt");
double sum = 0,value;
int count=0;
while(!inputfile.eof())
{
inputfile >> value;
sum+= value;
count++;
}
double avg = sum/count;
cout << "The Average of the numbers : " << avg << endl;
return 0;
}
I still can't the program to run. I have no idea why.
Explanation / Answer
please rate - thanks
program works fine.
you probably don't see it, because the window closes.
add system("pause"); to freeze the screen
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream inputfile;
inputfile.open("test.txt");
double sum = 0,value;
int count=0;
while(!inputfile.eof())
{
inputfile >> value;
sum+= value;
count++;
}
double avg = sum/count;
cout << "The Average of the numbers : " << avg << endl;
system("pause");
return 0;
}