homework not sure what to do

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
i'm not sure what i'm doing wrong here but nothing is displaying...
Assignment Objectives:
	Continued practice in passing arguments to functions
	Returning values from functions and using those values returned
	Continued practice in user-controlled looping
	Continued practice in decision making

Your Task: Read these specifications very carefully and construct your program accordingly. In order to get full credit for this assignment, you must follow this design model. Before you proceed, you should be familiar with the terminology used in chapter 5, such as arguments, return type, and return value.

You will write a program with the following functions:

Calc_Average – This function called calc_average will accept two float arguments. It will also return a float. The job of this function is to take in the two floats (representing a student’s midterm and final grades) as arguments, average them together, and return the student’s average (in the form of a float) back to main.

Letter_Grade – This function called letter_grade will accept one float argument. It will also return a char. The job of this function is to accept the float (representing a student’s average, which you will have gotten back from calc_grade) as an argument, assign a letter grade based on the student’s average (use 90-100 is an A, 80-89 is a B and so on…), and return the student’s letter grade (in the form of a char – ‘A’, ‘B’, ‘C’…) back to main.

Eligible – This function called eligible will accept one char argument. It will also return an int. The job of this function is to accept the char (representing a student’s letter grade, which you will have gotten back from letter_grade) as an argument and, if the grade is an ‘A’ (meaning the student is eligible for the President’s List) return a 1 back to main. If the grade is not an A, return a 0 back to main. Meanwhile, in main, you will keep a tally of eligible students (i.e. 1’s). Realize that the value returned by the eligible function can be added to a running total up in main.

Main—In main, you will start by asking the user how many students are in the class. You will then construct a loop (use your loop of choice) that will go as many times as that number entered. Here is some pseudocode you can use to program the inside of the loop:

//Get miderm grade for student x 
//Get final grade for student x
//Use calc_average to calculate student average; capture the return value in a variable; print the average on the screen
//Use letter_grade to assign a letter grade based on student average; capture the letter in a variable; print the letter grade on the screen
//Use eligible function to determine President List eligibility based on student’s letter grade; add the return value (either 0 or 1) to a running total. Remember that when we get a running total, we use our arithmetic assignment operators (e.g.+=).

Don’t forget to print the number of eligible students at the end of the program. 

Sample Output:

How many students in the class?: 3

Enter midterm grade for student 1: 80
Enter final grade for student 1: 95
Student 1's average: 87.5
Student 1's letter grade: B

Enter midterm grade for student 2: 90
Enter final grade for student 2: 92
Student 2's average: 91
Student 2's letter grade: A

Enter midterm grade for student 3: 90
Enter final grade for student 3: 94
Student 3's average: 92
Student 3's letter grade: A

Number of students eligible for the President's List: 2
Press any key to continue

Remember that when your function returns a value, your function call is always going to be part of a larger statement, such as an assignment statement. 

Example:

int x = somefunc(z);  //Where somefunc is a function that returns an integer. Remember, you’ve got to put it somewhere!

Also, do not use any global variables in this program! (see pages 202-203 in your book) 


my program so far



#include <iostream>
#include <string>
#include <stdlib.h>
#include <iomanip>
using namespace std;

float calc_average(float m, float f);
char letter_grade(float a);
float eligible(float t);
float students = 0;
char l = 0;

char AssignGrade(float letter_grade)
{
	char letter_grade = '\0';
	if (letter_grade >= 90)
		letter_grade = 'A';
	else if (letter_grade >= 80)
		letter_grade = 'B';
	else if (letter_grade >= 70)
		letter_grade = 'C';
	else if (letter_grade >= 60)
		letter_grade = 'D';
	else
		letter_grade = 'F';

	return  letter_grade;

}




int main()
{

	float mt = 0, fin = 0, avg = 0;
	char letter = '\0';
	int prezList = 0; 
	cout << "How many students in the class?: ";
	cin >> students;
	return students;

	cout << "Enter midterm grade for student 1:";
		cin >> mt;
		cout << "Enter final grade for student 1: ";
		cin >> fin;

		avg = calc_average(mt, fin); 

		letter = letter_grade(avg);

		prezList += eligible(letter);
		
		cout << "Student 1 Average:";
		cout << AssignGrade(avg) << endl;
		cout << "Student 1 letter grade: ";
		cout << letter_grade;

		cout << "Number of students eligible for the Presidents List: ";
	
		int eligible(char l);

		{

	if (l == 'A')

	{

		return 1;

	}

	else if (l /= 'A')

	{

		return 0;

	}

	return l;

}

	system("PAUSE");
	return 0;
}
float calc_average(float m, float f)
{
	float average = (m + f) / 2;

	return average;

}

float eligible(float t)
{
	return 0 ;
} 
Last edited on
Line 10: Why id students a float? Can you have a fraction of a student? The assignment said do NOT use globals. Why is this a global?

Line 13,15: You're creating a local variable with the same name as your argument. The local variable takes precedence. You won't be able to access the argument.

Line 15: You set letter_grade to 0. All your if tests are going to test against 0 always resulting in an 'F'.

Line 42: This return is going to cause the program to exit. Nothing past this point will be executed.

Line 62: Two problems.
1) You can't have nested functions.
2) The ; makes this a function declaration.

There are more problems, but this is as much as I'm going to call out with out code tags.

PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
Last edited on
ok so i started new some parts are still not working right... like how can i make it loop only the amount of times the user puts in. also the letter grade and the eligible list is coming up with letters and numbers in it...

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

#include <iostream>
#include <string>
#include <stdlib.h>
#include <iomanip>
using namespace std;

float calc_Average(float m, float f);
char letter_grade(float letter);
int eligible(char l);

int main()
{

	float mt = 0, fin = 0, avg = 0;
	char letter = '\0';
	int prezList = 0;
	int s =3;


	cout << "How many students are in the class?: ";
	cin >> s;

	do {
		cout << "Enter midterm grade:";
		cin >> mt;

		cout << "Enter final grade: ";
		cin >> fin;

		cout << "Students Average: ";
		avg = calc_Average(mt, fin);
		cout << avg << endl;

		cout << "students letter grade: ";
		cout << letter_grade << endl;


		cout << "Number of students eligible for President List: " << eligible << endl;
	} while (s);

	system("PAUSE");
	return 0; 

}

float calc_Average(float m, float f)
{
	float average = (m + f) / 2;

	return average;

}
char letter_grade(float a)
{
	char calc_grade = '/0';

	if (a <=100)
	{
		calc_grade = 'A';
	}
	else if (a <= 89)
	{
		calc_grade = 'B';

	}
	else if (a <= 79)
	{
		calc_grade = 'C';
	}
	else if (a <= 69)
	{
		calc_grade = 'D';
	}
	else if (a <= 60)
	{
		calc_grade = 'F';

	}
	else calc_grade = 'F';

	return calc_grade;

		

}

int eligible(char l)

{
	int PrezList = 0;

	if (l == 'A')

	{

		return 1;

	}

	else if (l /= 'A')

	{

		return 0;

	}

	return l;

}

Last edited on
Have a go with this :
while((s -= 1) > 0);
Does that help you? :)
Line 36: This is going to print the address of the function, not the result of the function call.
Should be:
 
  cout << letter_grade(avg) << endl;


Line 39: This is going to print the address of the function, not the result of the function call.
Also, this line is in the wrong place. This line should be after you've processed all the students.
Note that in order to call eligible, you need to pass the a letter grade, but you haven;t save the letter grade coming back from letter_grade().
You're also going to need a counter to count the number of students that are eligible for the president's list.

Line 91: This line is unnecessary. You don't use it.

Line 101: Your not equal operator is incorrect. It should be !=


all of this helped me out! the only problem i see now is that the grade always says "A". but i have to turn it in tonight. so thank you all!
closed account (48T7M4Gy)
.
Last edited on
Glad it helped :)
Topic archived. No new replies allowed.