Menu Program Help?

I run through the program once, entering all of the grades, but when I chose option 2 (line 77) the grades do not carry over, and it displays default, which I set to 0%. How can I fix this? The DisplayGrades function is at the bottom, by the way.

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
  /* This programs primary function is to present the user a menu, where he or she will enter their grades in ITCS 1212, and then the program
will, by using functions and math, calculate the users grade, and also present to them their grades in a tabular format. Use a while
loop in order to let the user chose multiple options per use. While will be used a lot in order to run the menu.
The menu will be the following:

1. Enter Grades
2. Display Grades
3. Show overall Grade
4. Exit the program



//Programming Assignment 1
*/

#include <iostream>
#include <iomanip>
using namespace std;

//Functions Prototypes declared
int menu();
void DisplayGrades (float, float, float, float, float, float); // In this function, it will display the grades the user enters. Used for choice 2.
float AssignmentGrade(float, float, float, float, float);
float LabTestGrade(float, float, float, float);                         // Prototypes to help me remember functions.
float LectureTestGrade(float, float, float, float, float);
float PostLabGrade(float, float, float, float, float, float, float, float, float, float);
float QuizGrade (float, float, float, float, float, float, float, float, float, float);
float ClickerGrade (float, float);
float grades(); // This function will add up all the grades and return letter and grade number. Used for choice 3. Adds return statements.




int main()
{
    float asgnment = 0, asgnment1 = 0, asgnment2 = 0, asgnment3 = 0,
        asgnment4 = 0, labtest = 0, labtest1 = 0, labtest2 = 0,
        labtest3 = 0, lecturetest = 0, lecturetest1 = 0, lecturetest2 = 0,   // Variables declared
        lecturetest3 = 0, lecturetest4 = 0, postlab = 0, p1 = 0, p2 = 0, p3 = 0, p4 = 0,
        p5 = 0, p6 = 0, p7 = 0, p8 = 0, p9 = 0, quiz = 0, quiz1 = 0, quiz2 = 0, quiz3 = 0, quiz4 = 0, quiz5 = 0,
        quiz6 = 0, quiz7 = 0, quiz8 = 0, quiz9 = 0, clicker = 0, clickergrade = 0;
    int choice;
    while(1)
    {
        choice = menu();
        if (choice ==4) break;
        switch (choice)

                    {
                                case 1:
                                AssignmentGrade(asgnment, asgnment1, asgnment2, asgnment3, asgnment4);
                                LabTestGrade(labtest, labtest1, labtest2, labtest3);
                                LectureTestGrade(lecturetest, lecturetest1,  lecturetest2, lecturetest3, lecturetest4); // Typed this out to help remind of what I used
                                PostLabGrade(postlab, p1, p2, p3, p4, p5, p6, p7, p8, p9);
                                QuizGrade(quiz, quiz1, quiz2, quiz3, quiz4, quiz5, quiz6, quiz7, quiz8, quiz9);
                                ClickerGrade (clickergrade, clicker);
                                break;
                                case 2:
                                DisplayGrades (asgnment, labtest, lecturetest, postlab, quiz, clickergrade);
    }

    }




return 0;
}

//Menu Options

int menu()
{
    int choice;
    cout << "Please select an option below." << endl << endl;
    cout << "1. Enter Grades" << endl;
    cout << "2. Display Grades" << endl;
    cout << "3. Show Overall Grade" << endl;
    cout << "4. Exit the Program"<< endl; // Will quit the program by using a while statement
    cout << "Enter your choice... ";
    cin >> choice;
    return choice;
}

//AssignmentGrade Function

float AssignmentGrade(float asgnment, float asgnment1, float asgnment2, float asgnment3, float asgnment4)
{
    cout << "Okay, lets get started!" << endl;
    cout << "Please enter your first assignment grade " << endl;
    cin >> asgnment1;
    cout << endl << "Enter your second assignment grade " << endl;
    cin >> asgnment2;
    cout << endl << "Enter your final assignment grade " << endl;
    cin >> asgnment3;
    asgnment = asgnment1*0.05 + asgnment2*0.05 + asgnment3 *0.05;
    cout << endl << "The average grade for assignments including weight is ";
    cout << asgnment << endl << endl;
    return asgnment;
}
// LabTestGrade Function

float LabTestGrade(float labtest, float labtest1, float labtest2, float labtest3)
{
  cout << "Now you are going to enter your 3 lab test grades. " <<endl;
  cout << "Please enter your first lab test score" <<endl;
  cin >> labtest1;
  cout << endl << "Now enter your second score" <<endl;
  cin >> labtest2;
  cout << endl << "Lastly, your final score" <<endl;
  cin >> labtest3;
  labtest = labtest1*0.10 + labtest2*0.10 + labtest3*0.10;
  cout << "Total points earned via lab tests including weight is... ";
  cout << labtest << endl << endl;
  return labtest;

}
// LectureTestGrade Function
float LectureTestGrade (float lecturetest, float lecturetest1, float lecturetest2, float lecturetest3, float lecturetest4)
{
  cout << "Next, you're going to enter your 4 Lecture Test grades." << endl;
  cout << "Please enter your first lecture test grade" << endl;
  cin >> lecturetest1;
  cout << endl << "Now enter your second grade" << endl;
  cin >> lecturetest2;
  cout << endl << "Next, your third score" << endl;
  cin >> lecturetest3;
  cout << endl << "Finally, your fourth score" << endl;
  cin >> lecturetest4;
  lecturetest = lecturetest1*0.10 + lecturetest2*0.10 + lecturetest3*0.10 + lecturetest4*0.10;
  cout << "Total points earned from lecture tests including weight is... ";
  cout << lecturetest << endl << endl;
  return lecturetest;
}
// PostLabGrade Function
float PostLabGrade(float postlab, float p1, float p2, float p3, float p4, float p5, float p6, float p7, float p8, float p9)
{
  cout << "Now, enter your 9 Post Lab grades" << endl;
  cin >> p1 >> p2 >> p3 >> p4 >> p5 >> p6 >> p7 >> p8 >> p9;
  postlab = p1*0.003 + p2*0.003 + p3*0.003 + p4*0.003 + p5*0.003 + p6*0.003 + p7*0.003 + p8*0.003 + p9*0.003;
  cout << "Total points earned from your 9 postlab assignments is ";
  cout << postlab << endl << endl;
  return postlab;

}
// QuizGrade Function
float QuizGrade (float quiz, float quiz1, float quiz2, float quiz3, float quiz4, float quiz5, float quiz6, float quiz7, float quiz8, float quiz9)
{
  cout << "9 more grades to enter, this time, please enter your quiz grades" << endl;
  cin >> quiz1 >> quiz2 >> quiz3 >> quiz4 >> quiz5 >> quiz6 >> quiz7 >> quiz8 >> quiz9;
  quiz = quiz1*0.004 + quiz2*0.004 + quiz3*0.004 + quiz4*0.004 + quiz5*0.004 + quiz6*0.004 + quiz7*0.004 + quiz8*0.004 + quiz9*0.004;
  cout << "Total points received from quizzes is ";
  cout << quiz << endl << endl;
  return quiz;
}
// ClickerGrade Function
float ClickerGrade (float clickergrade, float clicker)
{
  cout << "Almost done! Now, enter your total clicker grade." << endl;
  cin >> clicker;
  clickergrade = clicker*0.037;
  cout << "Points gained from clicker score is ";
  cout << clickergrade << endl << endl;
  return clickergrade;
}
// DisplayGrade Function // This is where it should show grades user entered in menu option 2
void DisplayGrades (float asgnment, float labtest, float lecturetest, float postlab, float quiz, float clickergrade)
{
cout << "Grades" << endl << endl;
cout  << "Assignment";
cout << std::right << std::setw(7)<< asgnment << "%" << endl;
cout  << "Lab Test";
cout << std::right << std::setw(9)<< labtest << "%" << endl;
cout << "Lecture";
cout << std::right << std::setw(10)<< lecturetest << "%" << endl;
cout << "Post Lab";
cout << std::right << std::setw(9)<< postlab << "%" << endl;
cout << "Quiz";
cout << std::right << std::setw(13)<< quiz << "%" << endl;
cout <<"Clicker";
cout << std::right << std::setw(10)<< clickergrade << "%" << endl;
}
Last edited on
Hi,

The trouble is that you call the functions in main, but don't assign them to anything.\

Good Luck !!
I'm still rather confused, the user inputs the values for the functions, correct?

EDIT* Nevermind, I figured it out. Thanks for the hint, heh.
Last edited on
So, everything works except for a new function I'm supposed to add, which is to add all of the grades in order to output a total. Its the float grade function, and its at the very bottom.

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
int menu();
void DisplayGrades (float, float, float, float, float, float); // In this function, it will display the grades the user enters. Used for choice 2.
float AssignmentGrade(float, float, float, float, float);
float LabTestGrade(float, float, float, float);                         // Prototypes to help me remember functions.
float LectureTestGrade(float, float, float, float, float);
float PostLabGrade(float, float, float, float, float, float, float, float, float, float);
float QuizGrade (float, float, float, float, float, float, float, float, float, float);
float ClickerGrade (float, float);
float grades(float, float, float, float, float, float, float); // This function will add up all the grades and return letter and grade number. Used for choice 3. Adds return statements.




int main()
{
    float asgnment = 0, asgnment1 = 0, asgnment2 = 0, asgnment3 = 0,
        asgnment4 = 0, labtest = 0, labtest1 = 0, labtest2 = 0,
        labtest3 = 0, lecturetest = 0, lecturetest1 = 0, lecturetest2 = 0,   // Variables declared
        lecturetest3 = 0, lecturetest4 = 0, postlab = 0, p1 = 0, p2 = 0, p3 = 0, p4 = 0,
        p5 = 0, p6 = 0, p7 = 0, p8 = 0, p9 = 0, quiz = 0, quiz1 = 0, quiz2 = 0, quiz3 = 0, quiz4 = 0, quiz5 = 0,
        quiz6 = 0, quiz7 = 0, quiz8 = 0, quiz9 = 0, clicker = 0, clickergrade = 0, grade = 0;
    int choice;
    while(1)
    {
        choice = menu();
        if (choice ==4) break;
        switch (choice)

                    {
                                case 1:
                               asgnment=AssignmentGrade(asgnment, asgnment1, asgnment2, asgnment3, asgnment4);
                               labtest = LabTestGrade(labtest, labtest1, labtest2, labtest3);
                               lecturetest = LectureTestGrade(lecturetest, lecturetest1,  lecturetest2, lecturetest3, lecturetest4); // Typed this out to help remind of what I used
                               postlab = PostLabGrade(postlab, p1, p2, p3, p4, p5, p6, p7, p8, p9);
                               quiz = QuizGrade(quiz, quiz1, quiz2, quiz3, quiz4, quiz5, quiz6, quiz7, quiz8, quiz9);
                               clickergrade = ClickerGrade (clickergrade, clicker);
                                break;
                                case 2:
                                DisplayGrades (asgnment, labtest, lecturetest, postlab, quiz, clickergrade);
                                break;
                                case 3:
                                grade = grades(grade, asgnment, labtest, lecturetest, postlab, quiz, clickergrade);
    }

    }




return 0;
}

//Menu Options

int menu()
{
    int choice;
    cout << "Please select an option below." << endl << endl;
    cout << "1. Enter Grades" << endl;
    cout << "2. Display Grades" << endl;
    cout << "3. Show Overall Grade" << endl;
    cout << "4. Exit the Program"<< endl;
    cout << "Enter your choice... ";
    cin >> choice;
    return choice;
}

//AssignmentGrade Function

float AssignmentGrade(float asgnment, float asgnment1, float asgnment2, float asgnment3, float asgnment4)
{
    cout << "Okay, lets get started!" << endl;
    cout << "Please enter your first assignment grade " << endl;
    cin >> asgnment1;
    cout << endl << "Enter your second assignment grade " << endl;
    cin >> asgnment2;
    cout << endl << "Enter your final assignment grade " << endl;
    cin >> asgnment3;
    asgnment = asgnment1*0.05 + asgnment2*0.05 + asgnment3 *0.05;
    cout << endl << "The average grade for assignments including weight is ";
    cout << asgnment << endl << endl;
    return asgnment;
}
// LabTestGrade Function

float LabTestGrade(float labtest, float labtest1, float labtest2, float labtest3)
{
  cout << "Now you are going to enter your 3 lab test grades. " <<endl;
  cout << "Please enter your first lab test score" <<endl;
  cin >> labtest1;
  cout << endl << "Now enter your second score" <<endl;
  cin >> labtest2;
  cout << endl << "Lastly, your final score" <<endl;
  cin >> labtest3;
  labtest = labtest1*0.10 + labtest2*0.10 + labtest3*0.10;
  cout << "Total points earned via lab tests including weight is... ";
  cout << labtest << endl << endl;
  return labtest;

}
// LectureTestGrade Function
float LectureTestGrade (float lecturetest, float lecturetest1, float lecturetest2, float lecturetest3, float lecturetest4)
{
  cout << "Next, you're going to enter your 4 Lecture Test grades." << endl;
  cout << "Please enter your first lecture test grade" << endl;
  cin >> lecturetest1;
  cout << endl << "Now enter your second grade" << endl;
  cin >> lecturetest2;
  cout << endl << "Next, your third score" << endl;
  cin >> lecturetest3;
  cout << endl << "Finally, your fourth score" << endl;
  cin >> lecturetest4;
  lecturetest = lecturetest1*0.10 + lecturetest2*0.10 + lecturetest3*0.10 + lecturetest4*0.10;
  cout << "Total points earned from lecture tests including weight is... ";
  cout << lecturetest << endl << endl;
  return lecturetest;
}
// PostLabGrade Function
float PostLabGrade(float postlab, float p1, float p2, float p3, float p4, float p5, float p6, float p7, float p8, float p9)
{
  cout << "Now, enter your 9 Post Lab grades" << endl;
  cin >> p1 >> p2 >> p3 >> p4 >> p5 >> p6 >> p7 >> p8 >> p9;
  postlab = p1*0.003 + p2*0.003 + p3*0.003 + p4*0.003 + p5*0.003 + p6*0.003 + p7*0.003 + p8*0.003 + p9*0.003;
  cout << "Total points earned from your 9 postlab assignments is ";
  cout << postlab << endl << endl;
  return postlab;

}
// QuizGrade Function
float QuizGrade (float quiz, float quiz1, float quiz2, float quiz3, float quiz4, float quiz5, float quiz6, float quiz7, float quiz8, float quiz9)
{
  cout << "9 more grades to enter, this time, please enter your quiz grades" << endl;
  cin >> quiz1 >> quiz2 >> quiz3 >> quiz4 >> quiz5 >> quiz6 >> quiz7 >> quiz8 >> quiz9;
  quiz = quiz1*0.004 + quiz2*0.004 + quiz3*0.004 + quiz4*0.004 + quiz5*0.004 + quiz6*0.004 + quiz7*0.004 + quiz8*0.004 + quiz9*0.004;
  cout << "Total points received from quizzes is ";
  cout << quiz << endl << endl;
  return quiz;
}
// ClickerGrade Function
float ClickerGrade (float clickergrade, float clicker)
{
  cout << "Almost done! Now, enter your total clicker grade." << endl;
  cin >> clicker;
  clickergrade = clicker*0.037;
  cout << "Points gained from clicker score is ";
  cout << clickergrade << endl << endl;
  return clickergrade;
}
// DisplayGrade Function
void DisplayGrades (float asgnment, float labtest, float lecturetest, float postlab, float quiz, float clickergrade)
{
cout << "Grades" << endl << endl;
cout  << "Assignment";
cout << std::right << std::setw(7)<< asgnment << "%" << endl;
cout  << "Lab Test";
cout << std::right << std::setw(9)<< labtest << "%" << endl;
cout << "Lecture";
cout << std::right << std::setw(10)<< lecturetest << "%" << endl;
cout << "Post Lab";
cout << std::right << std::setw(9)<< postlab << "%" << endl;
cout << "Quiz";
cout << std::right << std::setw(13)<< quiz << "%" << endl;
cout <<"Clicker";
cout << std::right << std::setw(10)<< clickergrade << "%" << endl;
}
// Grades Function
float grades( float grade, float asgnment, float labtest, float lecturetest, float postlab, float quiz, float clickergrade)
{
cout << "Total grade is " << grade << "%" << endl << endl;
grade = asgnment + labtest + lecturetest + postlab + quiz + clickergrade;

}
Hi,

Realise that the compiler compiles the statements in the order that you put them in the code. You are printing a value before you have calc'd it. But there is no need to have the function at all IMO (all the values exist in main), but if the assignment asks for it then I suppose you have to do it, no matter how trivial it is.

The function as it stands could be void, because you do all the printing inside of it. However, a function should do one conceptual thing: In this case calc the total; but you calc the total and print it. So better to calc the total in the function, return the value and do the printing in main.

Are you allowed to use arrays at all? That would improve the code big time, save having all those variables / arguments.

Prefer double rather than float, the precision of float is easily exceeded.

With the function declarations, I like to give the same names for the parameters as what is shown in the function definition. Not just a list of the types.

From a style POV, I like to put each parameter on it's own line, it's easier to read. The compiler doesn't care if you press the enter key in a statement, it's looking for the semicolon, parentheses or brace to denote the end of the statement. Also, the parameters should be marked const, it means you promise not to change the value of it inside the function:

1
2
3
4
5
6
7
void DisplayGrades (const double asgnment, 
                    const double labtest, 
                    const double lecturetest, 
                    const double postlab, 
                    const double quiz, 
                    const double clickergrade)
{
Last edited on
Topic archived. No new replies allowed.