Program compiler errors

I am getting some errors when compiling my program but I am unsure as to what to do to fix them. Any help or suggestions would be appreciated.

These are the errors:
Program4.cpp: In function `int main()':
Program4.cpp:23: error: expected primary-expression before "const"
Program4.cpp:23: error: expected `;' before "const"
Program4.cpp:24: error: `size' undeclared (first use this function)
Program4.cpp:24: error: (Each undeclared identifier is reported only once for each function it appears in.)
Program4.cpp:24: error: expected primary-expression before "double"
Program4.cpp:24: error: expected `;' before "double"
Program4.cpp:26: error: `scoreList' undeclared (first use this function)

The object of the program is to process the test scores of students in a class of 10 students.

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
#include <iostream>
using namespace std;

void readTestScores(double scoreList[], int size);
char getLetterGrade(double score);
void printComment(char grade);
void printTestResults(double scoreList[], int size);

int main()
{
    const int size{10};
    double scoreList[size]{};
    
    readTestScores(scoreList, size);
    printTestResults(scoreList, size);
    
}

void readTestScores(double scoreList[], int size)
{
    for(size = 0; size < 10; size++)
    {
        cout << "Enter Test Score " << size+1 << ": ";
        cin >> scoreList[size];
    }
}

char getLetterGrade(double score)
{
    char grade;
    if(score >= 90)
        grade = 'A';
    else if(score >= 80 && score < 90)
        grade = 'B';
    else if(score >= 70 && score < 80)
        grade = 'C';
    else if(score >= 60 && score < 70)
        grade = 'D';
    else if(score < 60)
        grade = 'F';
    return grade;
}

void printComment(char grade)
{
    switch(grade)
    {
        case 'A':
            cout << "Very Good" << endl;
            break;
        case 'B':
            cout << "Good" << endl;
            break;
        case 'C':
            cout << "Satisfactory" << endl;
            break;
        case 'D':
            cout << "Need Improvement" << endl;
            break;
        case 'F':
            cout << "Poor" << endl;
            break;
    };
}

void printTestResults(double scoreList[], int size)
{
    cout << "Test Score\tLetter Grade\tComment" << endl;
    cout << "----------\t------------\t-------" << endl;
    
    for(size = 0; size < 10; size++)
    {
        cout << scoreList[size] << "\t\t\t\t" << getLetterGrade(scoreList[size]) << "\t\t\t";
        printComment(getLetterGrade(scoreList[size]));
    }
}
These errors happens because your compiler seems using the C++ rules of a pre C++ 11 standard, and therefore it cannot handle assigning via type var {value};.

You could either change line 11 to const int size = 10;, or, if you use the clang++ or g++ compiler, then add to your compilation command a flag like -std=c++11 or -std=c++14 or -std=c++17.
Last edited on
Thanks! Got rid of the brackets and it works great
Topic archived. No new replies allowed.