/**************************************************** Write a program that reads in the file numbers.txt and prints out the average of the numbers there - for the moment let's force ourselves to do the average computation *after* we've read in the whole file. The file numbers .txt looks like this: N = 3 DATA: 67 61 82 I.e. there's a header that tells you how many numbers are in the file, and then you get all the numbers. ****************************************************/ #include <iostream> #include <fstream> #include <string> using namespace std; int main() { // Open input file, read header, get N = # of int's ifstream IN("numbers.txt"); char c; int N; string s; IN >> c >> c >> N >> s; // Create array A and read N int's from input int *A = new int[N]; for(int i = 0; i < N; i++) IN >> A[i]; // Cycle through array summing all the elements int sum = 0; for(int j = 0; j < N; j++) sum = sum + A[j]; // Print out the average cout << "The average of the values is " << double(sum)/N << endl; return 0; }