Help Passing input file into arrays

Pages: 12345
so i have this .. i had to use an ifstream on a previous program and i got it to work the way i am doing it now. would you like to see my program for that so you know where i am coming from ? here is what i have now

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <iomanip>

using namespace std;

const int SIZE = 100; // Maximum size of array
void inputFromFile(const double x[], int sz);
double CalculateMean(const double x[], int sz); // Mean of each category
double CalculateMax(const double x[], int sz); // Maximum of each category
double  CalculateSum(const double x[], int sz); // Sum of each category

int main(void)
{
    int Deaths[SIZE];
    int Doctors[SIZE];
    int Hospitals[SIZE];
    int Income[SIZE];
    int Population[SIZE];
    inputFromFile(Deaths, Doctors, Hospitals, Income, Population);
    
    
    ifstream health("health.txt");  // Open health.txt
    
string firstline;
    
// Read health.txt
    double Death, Docs, Hosp, Inc, Pop;
    
    
    
    
    if (health.is_open())
    {
        getline(health, firstline);
        
        while (!health.eof())
        {
        // Organize health.txt Data
            health >> Death >> Docs >> Hosp >> Inc >> Pop;
        }

    
}

    return 0; }
    
        double CalculateMean(const double x[], int sz)
        {
        double sum(0);
        
        for (int i=0; i<SIZE; i++)
        {
            sum += x[i];
        }
            return sum/SIZE;}


    double CalculateMax (const double x[], int sz)
    {
        double Max = x[0];
      
        for (int i=1; i<SIZE; i++)
        {
            if (x[i] > Max)
                Max = x[i];
        }
        return Max;
    }
i got my build to succeed with this but i didnt recieve an outpout... ugh haha sorry

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <iomanip>

using namespace std;

const int SIZE = 100; // Maximum size of array
void inputFromFile(const double x[], int sz);
double CalculateMean(const double x[], int sz); // Mean of each category
double CalculateMax(const double x[], int sz); // Maximum of each category
double  CalculateSum(const double x[], int sz); // Sum of each category

int main(void)
{
    
    
    ifstream health("health.txt");  // Open health.txt
    
string firstline;
    
// Read health.txt
    double Death, Docs, Hosp, Inc, Pop;
    
    
    
    
    if (health.is_open())
    {
        getline(health, firstline);
        
        while (!health.eof())
        {
        // Organize health.txt Data
            health >> Death >> Docs >> Hosp >> Inc >> Pop;
        }

    
}

    return 0; }
    
        double CalculateMean(const double x[], int sz)
        {
        double sum(0);
        
        for (int i=0; i<SIZE; i++)
        {
            sum += x[i];
        }
            return sum/SIZE;}


    double CalculateMax (const double x[], int sz)
    {
        double Max = x[0];
      
        for (int i=1; i<SIZE; i++)
        {
            if (x[i] > Max)
                Max = x[i];
        }
        return Max;
    }
The function signature that you wrote above. "sz" stands for my SIZE right ?

I probably should have named that cnt. It stands for the count of the number of records you actually read.
Hint: You're not counting the number of records you read.

If you were to pass SIZE as the second argument, you would still be using 100 in your calculations. If you only read 53 records, entries 53-99 in your arrays contain garbage.

Line 36: See my previous comment about not moving the values you read into the various arrays.

Lines 48,52,59: You're still using 100, even though you only have 53 records in the file.
Last edited on
"sz" stands for my SIZE right ?

No it stands for the number of elements, not necessarily the size of the array. The number of elements in an array can be less than or equal to the size of the array. You said you counted the number of elements in your file and found about 50, this number would be the number of elements.

You should be using this variable to limit the your loop instead of SIZE.
yes there is 53 rows of data . so in my OP i gave you 10 of the 53. so each row is an element ? not including the titles of each category. 53 rows of numbers and there are 5 columns. im not sure at all what you mean about line 36 because that was how i did it in a past program. maybe because i am using arrays now its different . i dont know
here is my past program about what i am talking about
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#include <fstream>
#include <string>
#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

int main()
{
    ifstream sampleGrades("sampleGrades.txt");  // Open sampleGrades.txt
    ofstream outputGrades("outputGrades.txt");  // Open outGrades.txt
    
    string firstLine;
    int TotalStudents;
    int ID = 0;
    
    // Read sampleGrades.txt
    double Attendance, hw1, hw2, hw3, hw4, hw5, hw6, hw7, exam1, exam2, finalExam;
    
    double GradePercent;
    
    double totalAp = 0, totalA = 0, totalAm = 0, AvgAttendanceA = 0.0;
    int countAp = 0, countA = 0, countAm = 0, AcountTot = 0;
    
    double totalBp = 0, totalB = 0, totalBm = 0, AvgAttendanceB = 0.0;
    int countBp = 0, countB = 0, countBm = 0, BcountTot = 0;
    
    double totalCp = 0, totalC = 0, totalCm = 0, AvgAttendanceC = 0.0;
    int countCp = 0, countC = 0, countCm = 0, CcountTot = 0;
    
    double totalD = 0, AvgAttendanceD = 0.0;
    int countD = 0, DcountTot = 0;
    
    double totalF = 0, AvgAttendanceF = 0.0;
    int countF = 0, FcountTot = 0;
    
    int NumA = 0;
    int NumB = 0;
    int NumC = 0;
    int NumD = 0;
    int NumF = 0;
    
    string LetterGrade = "";
    
   
    if (sampleGrades.is_open())
    {
        getline(sampleGrades, firstLine);
        
        sampleGrades >> TotalStudents;
       
        cout << "Number of Students In File: " << TotalStudents << endl;
        cout <<         "Letter  Count  Avg. Attendance"<< endl;
        
        outputGrades << "Number of Students In File: " << TotalStudents << endl;
        outputGrades << "ID   Course Grade  Letter Grade" << endl;
        
        
        while (!sampleGrades.eof())
        {
        // Organize sampleGrades.txt Data
            sampleGrades >> ID >> Attendance >> hw1 >> hw2 >> hw3 >> hw4 >> hw5 >> hw6 >> hw7 >> exam1 >> exam2 >> finalExam;
           
        // Students Letter Grade
            LetterGrade = "Error !! This is wrong !";
            
        // Students Grade Percentage
            GradePercent = 100*(Attendance*0.10/25 + (hw1 + hw2 + hw3 + hw4 + hw5 + hw6 + hw7)/700*0.35 + exam1/25*0.15 + exam2/25*0.15 + finalExam/40 * 0.25);
            
           
            if (GradePercent >= 97 && GradePercent <= 100)
            {
                LetterGrade = " A+ ";
                NumA++;
                totalAp += Attendance;
                countAp++;
            }
            else if (GradePercent >= 93 && GradePercent < 97)
            {
                LetterGrade = " A ";
                NumA++;
                totalA += Attendance;
                countA++;
            }
            else if (GradePercent >= 90 && GradePercent < 93)
            {
                LetterGrade = " A- ";
                NumA++;
                totalAm += Attendance;
                countAm++;
            }
            else if (GradePercent >= 87 && GradePercent < 90)
            {
                LetterGrade = " B+ ";
                NumB++;
                totalBp += Attendance;
                countBp++;
            }
            else if (GradePercent >= 83 && GradePercent < 87)
            {
                LetterGrade = " B ";
                NumB++;
                totalB += Attendance;
                countB++;
            }
            else if (GradePercent >= 80 && GradePercent < 83)
            {
                LetterGrade = " B- ";
                NumB++;
                totalBm += Attendance;
                countBm++;
            }
            else if (GradePercent >= 77 && GradePercent < 80)
            {
                LetterGrade = " C+ ";
                NumC++;
                totalCp += Attendance;
                countCp++;
            }
            else if (GradePercent >= 73 && GradePercent < 77)
            {
                LetterGrade = " C ";
                NumC++;
                totalC += Attendance;
                countC++;
            }
            else if (GradePercent >= 70 && GradePercent < 73)
            {
                LetterGrade = " C- ";
                NumC++;
                totalCm += Attendance;
                countCm++;
            }
            else if (GradePercent >= 60 && GradePercent < 70)
            {
                LetterGrade = " D ";
                NumD++;
                totalD += Attendance;
                countD++;
            }
            else if (GradePercent >= 0 && GradePercent < 60)
            {
                LetterGrade = " F ";
                NumF++;
                totalF += Attendance;
                countF++;
            }
            
       
    // Output ouputGrades.txt Data
        outputGrades << ID << '\t' << setprecision(2) << fixed << GradePercent << "%" << '\t' << '\t' << LetterGrade << endl;
            
    // Count Of Students W/ A Specific Grade
        AcountTot = countAp + countA + countAm;
        BcountTot = countBp + countB + countBm;
        CcountTot = countCp + countC + countCm;
        DcountTot = countD;
        FcountTot = countF;
            
    // Avg. Attendance For Students W/ A Specific Grade
        AvgAttendanceA = (totalAp + totalA + totalAm )/ (countAp + countA + countAm);
        AvgAttendanceB = (totalBp + totalB + totalBm) / (countBp + countB + countBm);
        AvgAttendanceC = (totalCp + totalC + totalCm) / (countCp + countC + countCm);
        AvgAttendanceD = totalD / countD;
        AvgAttendanceF = totalF / countF;
            
    }               // End Of While Loop
        
    // Output Xcode Screen Data
        cout << "  A" << setw(10) << AcountTot << setw(8) << AvgAttendanceA << endl;
        cout << "  B" << setw(10) << BcountTot << setw(10) << setprecision(2) << fixed << AvgAttendanceB << endl;
        cout << "  C" << setw(10) << CcountTot << setw(10) << AvgAttendanceC << endl;
        cout << "  D" << setw(10) << DcountTot << setw(10) << AvgAttendanceD << endl;
        cout << "  F" << setw(10) << FcountTot << setw(10) << AvgAttendanceF << endl;
        
    // Close sampleGrades.txt & ouputGrades.txt
        sampleGrades.close();
        outputGrades.close();
    
    }               // End of if statement
    
    
    return 0;
}
ok i fixed the SIZE i see what you mean here is the code but it doesnt output anything

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <iomanip>

using namespace std;

const int SIZE = 53; // Maximum size of array
double CalculateMean(const double x[], int cnt); // Mean of each category
double CalculateMax(const double x[], int cnt); // Maximum of each category
double  CalculateSum(const double x[], int cnt); // Sum of each category

int main(void)
{
    
    ifstream health("health.txt");  // Open health.txt
    
string firstline;
    
// Read health.txt
    double Death, Docs, Hosp, Inc, Pop;
    
    
    
    
    if (health.is_open())
    {
        getline(health, firstline);
        
        while (!health.eof())
        {
        // Organize health.txt Data
            health >> Death >> Docs >> Hosp >> Inc >> Pop;
        }

    
}

    return 0; }
    
        double CalculateMean(const double x[], int cnt)
        {
        double sum(0);
        
        for (int i=0; i<=cnt; i++)
        {
            sum += x[i];
        }
            return sum/cnt;}


    double CalculateMax (const double x[], int cnt)
    {
        double Max = x[0];
      
        for (int i=1; i<=cnt; i++)
        {
            if (x[i] > Max)
                Max = x[i];
        }
        return Max;
    }
Last edited on
it doesn't output anything

Well yeah. Where is there a single output statement in your program?

Lines 46,57: These are going to be out of bounds references. If cnt is 10, valid references are 0-9, not 1-10.

theres 53 rows of numbers. so cnt is <= 53. I realize that i havent a cout and thats why theres no output but i couldnt figure out where to put the cout's and how i can solve the mean and max for all 5 of my doubles. can you give me a hint please ?
Last edited on
theres 53 rows of numbers. so cnt is <= 53.

No. There are 53 rows. Those rows are 0-52. You want a < condiition, not <=. You had the condition right when you were using SIZE. Using <= will reference 54 entries (0-53).

Line 9. Leave SIZE at 100. What if rows are added to the text file? It wastes a little memory, but gives you flexibility to handle a data file up to 100 rows which is what was specified in the assignment.

What happened to your arrays?

Not sure why deaths is a fractional number in the data file. How can you have a fractional death?

This should get you started:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
int main ()
{   double Deaths[SIZE];    //  Changed to double to match input
    double Doctors[SIZE];
    double Hospitals[SIZE];
    double Income[SIZE];    //  Changed to double to match input
    double Population[SIZE];    
    ifstream health("health.txt");  // Open health.txt
    string firstline;  
    int     cnt = 0;
    double  MeanDeaths; 
    
    //  Check if open failed
    if (! health.is_open())
    {   cout << "Failed to open input file" << endl;
        return 1;
    }
    //  Eat the column headers
    getline(health, firstline);
    
    //  Read the input 
    //  Note that we don't use eof()        
    while (health >> Deaths[cnt] >> Doctors[cnt] >> Hospitals[cnt] >> Income[cnt] >> Population[cnt])
    {   cnt++;      //  Increment numbeer of records read
    }
    
    MeanDeaths = CalculateMean (Deaths, cnt);
    cout << "Mean deaths = " << MeanDeaths << endl;
    //  Perform other calculations and outputs here
    system ("pause");
    return 0; 
}

Last edited on
What happens if there are more than SIZE entries in the file?
thank you abstraction i will work with what you gave me. the reason i have fractional deaths is because the mean is essentially the avg so i divided the sum by the number of rows. That is wrong ? also i changed SIZE because jib suggested that because i only have 53 rows of data + 1 row as the Deaths, income, pop etc etc that i shouldnt have SIZE = 100 or else i misunderstood what he said. this assignment is due tomorrow by 5pm so im sorta screwed but i am goingto be working on this all today and tomorrow. thank you abstraction i will post back on here if i ave any other issues
also i changed SIZE because jib suggested that because i only have 53 rows of data + 1 row as the Deaths, income, pop etc etc that i shouldnt have SIZE = 100 or else i misunderstood what he said.

Yes you misunderstood what I said. You need to understand that the size of the array can be different from the number of elements that the array actually contains. The size is fixed, the number of elements in the array can vary from none to the size of the array.
o ok jib i understand . i apologize.
- abstraction here is what i came up with. i am just working with what you gave me until i know that it works then i will make it in my own way but is this right because i dont think i wrote the functions below return 0; right

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <iomanip>

using namespace std;

const int SIZE = 100; // Maximum size of array
double CalculateMean(const double x[], int cnt); // Mean of each category
double CalculateMax(const double x[], int cnt); // Maximum of each category
double  CalculateSum(const double x[], int cnt); // Sum of each category

int main ()
{   double Deaths[SIZE];    //  Changed to double to match input
    double Doctors[SIZE];
    double Hospitals[SIZE];
    double Income[SIZE];    //  Changed to double to match input
    double Population[SIZE];
    ifstream health("health.txt");  // Open health.txt
    string firstline;
    int     cnt = 0;
    double  MeanDeaths, MeanDoctors, MeanHospitals, MeanIncome, MeanPopulation;
    double MaxDeaths, MaxDoctors, MaxHospitals, MaxIncome,MaxPopulation;
    double SumDeaths, SumDoctors, SumHospitals, SumIncome, SumPopulation;
    
    //  Check if open failed
    if (! health.is_open())
    {   cout << "Failed to open input file" << endl;
        return 1;
    }
    //  Eat the column headers
    getline(health, firstline);
    
    //  Read the input
    //  Note that we don't use eof()
    while (health >> Deaths[cnt] >> Doctors[cnt] >> Hospitals[cnt] >> Income[cnt] >> Population[cnt])
    {   cnt++;      //  Increment numbeer of records read
    }
    
    MeanDeaths = CalculateMean (Deaths, cnt);
    cout << "Mean deaths = " << MeanDeaths << endl;
    MeanDoctors = CalculateMean (Doctors, cnt);
    cout << "Mean doctors = " << MeanDoctors << endl;
    MeanHospitals = CalculateMean (Hospitals, cnt);
    cout << "Mean hospitals = " << MeanHospitals << endl;
    MeanIncome = CalculateMean (Income, cnt);
    cout << "Mean income = " << MeanIncome << endl;
    MeanPopulation = CalculateMean (Population, cnt);
    cout << "Mean population = " << MeanPopulation << endl;
    
    MaxDeaths = CalculateMax (Deaths, cnt);
    cout << "Max Deaths = " << MaxDeaths << endl;
    MaxDoctors = CalculateMax (Doctors, cnt);
    cout << "Max doctors = " << MaxDoctors << endl;
    MaxHospitals = CalculateMax (Hospitals, cnt);
    cout << "Max hospitals = " << MaxHospitals << endl;
    MaxIncome = CalculateMax (Income, cnt);
    cout << "Max income = " << MaxIncome << endl;
    MaxPopulation = CalculateMax (Population, cnt);
    cout << "Max population = " << MaxPopulation << endl;
    
    SumDeaths = CalculateSum(Deaths, cnt);
    cout << "Sum deaths = " << SumDeaths << endl;
    SumDoctors = CalculateSum(Doctors, cnt);
    cout << "Sum doctors = " << SumDoctors << endl;
    SumHospitals = CalculateSum(Hospitals, cnt);
    cout << "Sum hospitals = " << SumHospitals << endl;
    SumIncome = CalculateSum(Income, cnt);
    cout << "Sum income = " << SumIncome << endl;
    SumPopulation = CalculateSum(Population, cnt);
    cout << "Sum population = " << SumPopulation << endl;
    
    
   
    //  Perform other calculations and outputs here
    system ("pause");
    return 0;
}
    
        double CalculateMean(const double x[], int cnt)
        {
        double sum(0);
        
        for (int i=0; i<SIZE; i++)
        {
            sum += x[i];
        }
            return sum/cnt;}


    double CalculateMax (const double x[], int cnt)
    {
        // Determine local objects
        double Max;
        
        // Determine maximum value in the array
        Max = x[0];
        for (int i=1; i<SIZE; i++)
        {
            if (x[i] > Max)
                Max = x[i];
        }
        // Return maximum value. /
        return Max;
    }
    
      double CalculateSum(const double x[], int cnt)
{
        double sum = 0.0;
    
        for (int i=0; i<SIZE; i++)
    {
            sum += x[i];
    }
    return sum;

}
Last edited on
this is what i got when i ran it the means are right. but i didnt even get an output for my max and sum. just 11db

Mean deaths = 9.30566
Mean doctors = 116.094
Mean hospitals = 589.792
Mean income = 9.43585
Mean population = 110.642
(lldb) 


it should look like this
mean max sum of DEATH =       9.31      12.80     493.20
mean max sum of DOC   =     116.09     238.00    6153.00
mean max sum of HOSP  =     589.79    1792.00   31259.00
mean max sum of INCOM =       9.44      13.00     500.10
mean max sum of POPUL =     110.64     292.00    5864.00
Last edited on
lines 85,97,109: You're still not understanding the difference between SIZE and cnt.
SIZE is the maximum capacity of your arrays.
cnt is the number of valid entries in those arrays.

The loops in your calculate functions are calculating results based on uninitialized entries in your arrays. If you read in 53 records, cnt=53. Only array[0] though array[52] are valid. array[53] through array[99] are UNINITIALIZED. You never store anything in them. How can you possibly compute an accurate result when you're including uninitialized values in your calculation?
Last edited on
ok that sort of makes sense to me. but my mean calculation was correct when using SIZE on line 85.
- if i am using SIZE wrong where am i supposed to use it? you told me to keep my const int SIZE =100 correct ? i am obviously confused... ugh sorry. ill try to make sense of your post. thank you
- i do understand the difference between SIZE and cnt. i am just confused on how to implement that into my program to output the results i am looking for is all.
Last edited on
i changed my SIZE in lines 85, 99 and 112 to cnt . and it did output the correct answer for my mean which threw me off. i apologize. so my code is now:
- i still get a debugging error. i keep playing with it though to try and figure it out . im trying i do promise that
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <iomanip>

using namespace std;

const int SIZE = 100; // Maximum size of array
double CalculateMean(const double x[], int cnt); // Mean of each category
double CalculateMax(const double x[], int cnt); // Maximum of each category
double  CalculateSum(const double x[], int cnt); // Sum of each category

int main ()
{   double Deaths[SIZE];    //  Changed to double to match input
    double Doctors[SIZE];
    double Hospitals[SIZE];
    double Income[SIZE];    //  Changed to double to match input
    double Population[SIZE];
    ifstream health("health.txt");  // Open health.txt
    string firstline;
    int cnt = 0;
    double MeanDeaths, MeanDoctors, MeanHospitals, MeanIncome, MeanPopulation;
    double MaxDeaths, MaxDoctors, MaxHospitals, MaxIncome,MaxPopulation;
    double SumDeaths, SumDoctors, SumHospitals, SumIncome, SumPopulation;
    
    //  Check if open failed
    if (! health.is_open())
    {   cout << "Failed to open input file" << endl;
        return 1;
    }
    //  Eat the column headers
    getline(health, firstline);
    
    //  Read the input
    //  Note that we don't use eof()
    while (health >> Deaths[cnt] >> Doctors[cnt] >> Hospitals[cnt] >> Income[cnt] >> Population[cnt])
    {   cnt++;      //  Increment numbeer of records read
    }
    
    MeanDeaths = CalculateMean (Deaths, cnt);
    cout << "Mean deaths = " << MeanDeaths << endl;
    MeanDoctors = CalculateMean (Doctors, cnt);
    cout << "Mean doctors = " << MeanDoctors << endl;
    MeanHospitals = CalculateMean (Hospitals, cnt);
    cout << "Mean hospitals = " << MeanHospitals << endl;
    MeanIncome = CalculateMean (Income, cnt);
    cout << "Mean income = " << MeanIncome << endl;
    MeanPopulation = CalculateMean (Population, cnt);
    cout << "Mean population = " << MeanPopulation << endl;
    
    MaxDeaths = CalculateMax (Deaths, cnt);
    cout << "Max Deaths = " << MaxDeaths << endl;
    MaxDoctors = CalculateMax (Doctors, cnt);
    cout << "Max doctors = " << MaxDoctors << endl;
    MaxHospitals = CalculateMax (Hospitals, cnt);
    cout << "Max hospitals = " << MaxHospitals << endl;
    MaxIncome = CalculateMax (Income, cnt);
    cout << "Max income = " << MaxIncome << endl;
    MaxPopulation = CalculateMax (Population, cnt);
    cout << "Max population = " << MaxPopulation << endl;
    
    SumDeaths = CalculateSum(Deaths, cnt);
    cout << "Sum deaths = " << SumDeaths << endl;
    SumDoctors = CalculateSum(Doctors, cnt);
    cout << "Sum doctors = " << SumDoctors << endl;
    SumHospitals = CalculateSum(Hospitals, cnt);
    cout << "Sum hospitals = " << SumHospitals << endl;
    SumIncome = CalculateSum(Income, cnt);
    cout << "Sum income = " << SumIncome << endl;
    SumPopulation = CalculateSum(Population, cnt);
    cout << "Sum population = " << SumPopulation << endl;
    
    
   
    //  Perform other calculations and outputs here
    system ("pause");
    return 0;
}
    
        double CalculateMean(const double x[], int cnt)
        {
        double sum(0);
        
        for (int i=0; i<cnt; i++)
        {
            sum += x[i];
        }
            return sum/cnt;}


    double CalculateMax (const double x[], int cnt)
    {
        // Determine local objects
        double Max;
        
        // Determine maximum value in the array
        Max = x[0];
        for (int i=1; i<cnt; i++)
        {
            if (x[i] > Max)
                Max = x[i];
        }
        // Return maximum value. /
        return Max;
    }

    double CalculateSum(const double x[], int cnt)
{
        double sumOfFile = 0.0;
    
        for (int i=0; i<cnt; i++)
    {
            sumOfFile += x[i];
    }
    return sumOfFile;
I ran your program as posted and had no problems using the 10 record file you provided in your first post.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Mean deaths = 9.22
Mean doctors = 91.3
Mean hospitals = 635.7
Mean income = 8.85
Mean population = 139.1
Max Deaths = 11.7
Max doctors = 168
Max hospitals = 1792
Max income = 10.9
Max population = 206
Sum deaths = 92.2
Sum doctors = 913
Sum hospitals = 6357
Sum income = 88.5
Sum population = 1391

canyou try it with this please because i cant get it to work . only the mean then 11db
here is the whole thing:
Deaths Doctors Hosp Income Population
8.00 78 284 9.10 109
9.30 68 433 8.70 144
7.50 70 739 7.20 113
8.90 96 1792 8.90 97
10.20 74 477 8.30 206
8.30 111 362 10.90 124
8.80 77 671 10.00 152
8.80 168 636 9.10 162
10.70 82 329 8.70 150
11.70 89 634 7.60 134
8.50 149 631 10.80 292
8.30 60 257 9.50 108
8.20 96 284 8.80 111
7.90 83 603 9.50 182
10.30 130 686 8.70 129
7.40 145 345 11.20 158
9.60 112 1357 9.70 186
9.30 131 544 9.60 177
10.60 80 205 9.10 127
9.70 130 1264 9.20 179
11.60 140 688 8.30 80
8.10 154 354 8.40 103
9.80 118 1632 9.40 101
7.40 94 348 9.80 117
9.40 119 370 10.40 88
11.20 153 648 9.90 78
9.10 116 366 9.20 102
10.50 97 540 10.30 95
11.90 176 680 8.90 80
8.40 75 345 9.60 92
5.00 134 525 10.30 126
9.80 161 870 10.40 108
9.80 111 669 9.70 77
10.80 114 452 9.60 60
10.10 142 430 10.70 71
10.90 238 822 10.30 86
9.20 78 190 10.70 93
8.30 196 867 9.60 106
7.30 125 969 10.50 162
9.40 82 499 7.70 95
9.40 125 925 10.20 91
9.80 129 353 9.90 52
3.60 84 288 8.40 110
8.40 183 718 10.40 69
10.80 119 540 9.20 57
10.10 180 668 13.00 106
9.00 82 347 8.80 40
10.00 71 345 9.20 50
11.30 118 463 7.80 35
11.30 121 728 8.20 86
12.80 68 383 7.40 57
10.00 112 316 10.40 57
6.70 109 388 8.90 94
Pages: 12345