I am getting exponential numbers for the first squared average and variance, while the second part is not even counting the positive numbers. I am looking for help, here's a example of the file to read.

-6

1

-5

-7

-7

6

3

-4

-1

-7

-7

1

5

-2

-4

-3

8

1

-4

9

My current code:

#include <iostream> #include <iomanip> #include <fstream> #include <cmath> #include <string> using namespace std; int main() { cout << "Part One" << endl; double arr[100], avg, x; //var's are: arr[0], arr[1] ... arr[19] int count, i; ifstream inf; inf.open("c:\\temp\\program4_data.txt"); if (!inf) { cout << "problem with input file: c:\\temp\\program4_data.txt"; system("pause"); exit(0); } count=0; while (inf >>arr[count]) count++; double k=0.00; for(int i=0; i<count;i++) k+=arr[i]; avg=k/count; double sqravg1; double sqravg; double var1; x=20; sqravg1=0; for(int i=0; i<count; i=i+1) sqravg1+=((arr[i+1]*arr[i+1])); sqravg=sqravg1/count; cout << "Count" << setw(23) << "=" << count << endl; cout << "Average" << setw(21) << "=" << avg <<endl; cout << "Average of sqaures" << setw(10) << "=" << sqravg << endl; var1=sqravg-avg; cout << "Variance" << setw(20) << "=" << var1 << endl; cout << endl; cout << "Part 2" << endl; cout << endl; count=0; inf.close(); inf.open("c:\\temp\\program4_data.txt"); while (inf >>arr[count]) if (arr[count]>0)count++; inf.close(); double avg1; avg1=0; for(int i=0; i<count; i=i+1) avg1+=((arr[i+1])) ; avg = avg1/count; sqravg1=0; for(int i=0; i<count; i=i+1) sqravg1+=((arr[i+1]*arr[i+1])); sqravg=sqravg1/count; cout << "Count" << setw(23) << "=" << count << endl; cout << "Average" << setw(21) << "=" << avg <<endl; cout << "Average of sqaures" << setw(10) << "=" << sqravg << endl; var1=sqravg-avg; cout << "Variance" << setw(20) << "=" << var1 << endl; cout << endl; system("pause"); }