Hellow
I'm new to this forum, and I like it alot
It is just what I was looking for
I'm new at c++
for now, I'm at input/output files
and I have a problem
I have to write a program that reads some numbers (type double) from a file and outputs the avarage of it
"Read numbers from the input file in a loop, incrementing count and updating sum with each number read."
How do I have to read ALL files from the file
can someone tell me how the loop has to look like
here is my code so far
Code:#include <fstream> #include <iostream> #include <cstdlib> using namespace std; int main() { ifstream fin; int count = 0; double val; double sum = 0.0; fin.open("numbers02.txt"); //HERE HAS TO COME THE LOOP fin.close(); if (count > 0) { cout << "Average of the " << count << " numbers in the file is " << (sum/count) << "\n"; } else { cout << "No numbers were found"; } }
I'm new with files ... that's why I have problems