Help with input File. Urgent!

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
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
#include <ostream>

using namespace std;

const int NUMBER_OF_PEOPLE = 10;
const int NUMBER_OF_TESTS = 5;

void read(string name[], int namesSize, double scores[][NUMBER_OF_TESTS], int scoresRowSize)
{
    ifstream infile;
    infile.open("input.txt");
    
    int counterNames =0, counterScores = 0;
    
    while(counterNames < namesSize)
    {
        infile >> name[counterNames];
        while( counterScores < NUMBER_OF_TESTS)
        {
            infile >> scores[counterNames][counterScores];
            counterScores++;
        }
        counterScores = 0;
        counterNames++;
    }
}

void calculate(double matrix[], double scores[][NUMBER_OF_TESTS], int scoresRow_Size)
{
    int counter = 0, num = 0;
    double total = 0, average = 0;
    cout << fixed << showpoint << setprecision(2) << endl;
    
    while (counter < scoresRow_Size)
    {
        while (num < NUMBER_OF_TESTS)
        {
            total = total + scores[counter][num];
            num++;
        }
        average = (total/NUMBER_OF_TESTS);
        matrix[counter] = average;
        total = 0;
        average = 0;
        num = 0;
        counter++;
    }
}

void print(double matrix[], string names[], int namesSize)
{
    cout << setw(10) << "Name" << setw(12) << "Grade" << endl;
    int counter = 0;
    
    while (counter < namesSize)
    {
        cout << setw(10) << names[counter] << setw(12) << matrix[counter] << endl;
        counter++;
    }
}

int main()
{
    string names[NUMBER_OF_PEOPLE];
    double scores[NUMBER_OF_PEOPLE][NUMBER_OF_TESTS];
    double grades[NUMBER_OF_PEOPLE];
    
    read(names, 10, scores, 10);
    calculate(grades, scores, 10);
    print(grades, names, 10);
    
    return 0;
}


What is wrong with my coding?
When I test the program, the output is...
Name Grade
0.00
0.00
0.00
0.00
0.00
0.00
0.00
0.00
0.00

Why aren't the names visible, and grades accurate?


Also, here is my txt document "input.txt"
1
2
3
4
5
6
7
8
9
10
Johnson 85 83 77 91 76
Aniston 80 90 95 93 48
Cooper 78 81 11 90 73
Gupta 92 83 30 69 87
Blair 23 45 69 38 59
Clark 60 85 45 39 67
Kennedy 77 31 52 74 83
Bronson 93 94 89 77 97
Sunny 79 85 28 93 82
Smith 85 72 49 75 63
Add some debug logging. Have the code output things like "File opened successfully" or "Cannot find file" and "Reading input from file... have read the following value: XXXXX" and other such useful logging.
Topic archived. No new replies allowed.