Undeclared identifier in grading program

I'm trying to add a menu to my previous program as well as make it more modular by turning the screens into functions.

I don't know where I am going wrong to now be getting errors, I suspect I need to move something up to have it be declared beforehand but unsure what exactly it would be.

Keep in mind I'm just a noob and trying to emulate a similar program my professor made previously.

Code that gives error atm:

https://gist.github.com/Newtochr/2e0aa3246c895d4fa3d18ccb9300c4e5

Before attempting to modularize code into functions with a menu:

https://gist.github.com/Newtochr/d5223a4bf54e748bd32f3031377889a9
You should post your actual error message(s) as well.
Your errors are mainly undeclared identifiers:
For example in
1
2
void output_scrn
double Average = (grade1_num + grade2_num + grade3_num + grade4_num + grade5_num + grade6_num) / 6.0;

All the the vars grade1_num, grade2_num.... are undefined;

There is one missing '\n' or ' ' at the line elsedouble Average = (grade1_num + grade2_num + grade3_num + grade4_num + grade5_num + grade6_num) / 6.0;
This is your code after having removing all the unused declarations and having done some tweaking. It’s still wrong, but it can be read quicker.
I don’t want to stifle your artistic disposition, but if you think your teacher will be impressed by the time and effort you put into data presentation, be ready to be bitterly disappointed. You’d better focus on making the code working and listening to the compiler warnings.

Do declare the variables in the proper function.
Choose between passing by value and by reference.
Don’t initialize objects which don’t need to be initialized.
Calling the ‘menu’ function from main() is ok, but than menu_scrn() should accomplish some real task.

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


// Prototypes --------------------------------------------------------------------
void menu_scrn();

void output_scrn( const std::string& last,
                  const std::string& first,
                  const std::string& csid,
                  const std::string& grade1,
                  const std::string& grade2,
                  const std::string& grade3,
                  const std::string& grade4,
                  const std::string& grade5,
                  const std::string& grade6 );
void error_scrn();


int main()
{
    menu_scrn();
}


void menu_scrn()
{
    std::string last;
    std::string first;
    std::string csid;
    std::string grade1;
    std::string grade2;
    std::string grade3;
    std::string grade4;
    std::string grade5;
    std::string grade6;
    std::string ans;
    do {
        std::cout << "\n\n"
                     "                                  Random College\n"
                     "                         STUDENT GRADE TRACKING SYSTEM\n"
                     "                                ( Main Menu )\n\n\n"
                     "                                 <I>nput Student Information"
                     "                                 <O>utput Average Grades"
                     "                                 <E>xit\n\n\n\n\n"
                     "                                 Enter I, O, or E: ";
        getline(std::cin, ans);

        switch (ans.at(0)) {
        case 'I':
        case 'i':
            std::cout << "\n"
                         "                                  Random\n"
                         "                         STUDENT GRADE TRACKING SYSTEM\n"
                         "                                ( Input Screen )\n\n"
                         " ----------------------------------------------------------------------------- \n\n"
                         "                   Please press <ENTER> after inputting data\n\n"
                         "                   Last Name:  ";
            std::getline(std::cin, last);
            std::cout << "                   First Name:  ";
            std::getline(std::cin, first);
            std::cout << "\n                   Student ID Number (10-Digit):  ";
            std::getline(std::cin, csid);
            std::cout << "\n ----------------------------------------------------------------------------- \n\n"
                         "                                  Grade 1:  ";
            std::getline(std::cin, grade1);
            std::cout << "                                  Grade 2:  ";
            std::getline(std::cin, grade2);
            std::cout << "                                  Grade 3:  ";
            std::getline(std::cin, grade3);
            std::cout << "                                  Grade 4:  ";
            std::getline(std::cin, grade4);
            std::cout << "                                  Grade 5:  ";
            std::getline(std::cin, grade5);
            std::cout << "                                  Grade 6:  ";
            std::getline(std::cin, grade6);
            std::cout << "\n\n";
            break;

        case 'O':
        case 'o':
            output_scrn(last, first, csid, grade1, grade2, grade3, grade4, grade5, grade6);
            break;

        case 'E':
        case 'e':
            break;

        default:
            error_scrn();
        } // !switch
    } while (toupper(ans.at(0)) != 'E');
}


void output_scrn( const std::string& last,
                  const std::string& first,
                  const std::string& csid,
                  const std::string& grade1,
                  const std::string& grade2,
                  const std::string& grade3,
                  const std::string& grade4,
                  const std::string& grade5,
                  const std::string& grade6 )
{
    double Average = (grade1_num + grade2_num + grade3_num + grade4_num + grade5_num + grade6_num) / 6.0;
    {
        if      (Average >  100) { letter_grade = '+'; }
        else if (Average >=  90) { letter_grade = 'A'; }
        else if (Average >=  80) { letter_grade = 'B'; }
        else if (Average >=  70) { letter_grade = 'C'; }
        else if (Average >=  60) { letter_grade = 'D'; }
        else if (Average >=  50) { letter_grade = 'E'; }
        else if (Average >=   0) { letter_grade = 'F'; }
        else                     { letter_grade = '-'; }
    }

    std::cout << "\n                                  Random College\n"
                 "                         STUDENT GRADE TRACKING SYSTEM\n"
                 "                                ( Output Screen )\n";
    std::cout << R"(
                                  90 - 100 -> A
                                  80 - 90  -> B
                                  70 - 80  -> C
                                  60 - 70  -> D
                                  50 - 60  -> E
                                  less than 50 -> F
                         ----------------------------------      
)";
    std::cout << "     Student Name (Last, First):  " << last
              << ' ' << first << '\n'
              << "     CSID:  " << csid << "\n\n"
              << "                                  Grade 1:  " << grade1 << '\n'
              << "                                  Grade 2:  " << grade2 << '\n'
              << "                                  Grade 3:  " << grade3 << '\n'
              << "                                  Grade 4:  " << grade4 << '\n'
              << "                                  Grade 5:  " << grade5 << '\n'
              << "                                  Grade 6:  " << grade6 << '\n'
              << "\n                      Total Grade Average:  " << Average
              << "           Letter Grade:  " << letterGrade << '\n';
    if (Average > 100) {
        letterGrade = '+';
        std::cout << "                   Error: Grade cannot be more than 100";
    }
    if (Average < 0) {
        letterGrade = '-';
        std::cout << "                   Error: Grade cannot be less than 0";
    }
    std::cout << '\n';
}


void error_scrn()
{
    std::cout << "\n                                  Random College\n"
                 "                         STUDENT GRADE TRACKING SYSTEM\n"
                 "                                ( Error Screen )\n\n\n"
                 "----------------------------------------------------------------------------"
                 "\n                   Error: Enter I, O, or E!\n";
}

Topic archived. No new replies allowed.