Homework help

Hey guys new C++ college student here needing help with an assignment. I have to display the letter grade obtained from the average of the scores and the lowest score in the file. I realize I don't have any code for the lowest grade. That's because I don't know how to do it. Also why is the letter grade not showing? It's just blank. Any help would be really appreciated...its due tonight :(

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
  /*

Programmer name:	Kris Rossman
date:				11/15/2013
assignment:			Lab 11 Part 3

description:		Gym Membership                                                     
	
INPUTS:
	cin - menu option, # of months                          
OUTPUTS:
	cout - message to the user based on menu option.                         
*/
#include <cstdlib>
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
#include <time.h>
#include <cmath>
#define myDate 		"November 15th, 2013            "
#define myActivity  "Lab 11 Part 3                  "
#define line1  "   This program is a menu listing the types of     "
#define line2  "   gym membership.  User may enter a option and a  "
#define line3  "   message is displayed.                           "
#define over2  "\t\t"
#define over3  "\t\t\t"
#define over4  "\t\t\t\t"
#define down5  "\n\n\n\n\n"
#define down8  "\n\n\n\n\n\n\n\n"
#define down10 "\n\n\n\n\n\n\n\n\n\n"
#define down11 "\n\n\n\n\n\n\n\n\n\n\n"
#define down12 "\n\n\n\n\n\n\n\n\n\n\n\n"                                                  

using namespace std;


void welcome();
void splash();  
void getGrade(float);

int main(int argc, char *argv[]) 
{
	string filename;
	ifstream infile;
	int score, count = 0, total = 0;
	float average;
	char grade;
	
	splash();
	welcome();
	
	
	cout << showpoint << setprecision(1) << fixed;
	
	system("CLS");
	cout << down11
	 	 << over3 << "Enter a file name: ";
	cin >> filename;
	
	infile.open(filename.c_str());
	system("CLS");
	cout << down5;
	
			cout << over4 << "Scores Summary" << endl;
			cout << over4 << "--------------" << endl;
			
	if (infile)
	{
		while (!infile.eof())
		{
			infile >> score;
			if (score >= 0 && score <= 100)
			{
				
				count++;
				total += score;
				cout << over4 << "Score " << count << ":" << setw(8) << score << endl;
				
			}
		}
		average = total / static_cast<double>(count);
		
		
		cout << over4 << "Number of scores = " << count << endl;
		cout << over4 << "Scores total     = " << total << endl;
		cout << over4 << "Average          = " << average << "%" << endl;
		cout << over4 << "Lowest Score     = " << endl;
		getGrade(average);
			}
	else
	{
		cout << over3 << "\"" << filename
			 << "\" could not be found!";
	}
	

	
	
	return 0;
}
void getGrade(float average)
{
	float num;
	const float A = 90.00,
			    B = 80.00,
			    C = 70.00,
			    D = 60.00;
	char grade;
	
	if (num >= A)
		grade = 'A';
	else if (num >= B)
		grade = 'B';
	else if (num >= C)
		grade = 'C';
	else if (num >= D)
		grade = 'D';
		
	cout << over4 << "Grade            = " << grade << endl;	

}

void splash ()
{
	system("CLS");
	cout << "\n\n\n"
		 << "\n\t\t	       _ "	 
		 << "\n\t\t              (_)          _ "
		 << "\n\t\t          _         .=.   (_) "
		 << "\n\t\t         (_)   _   //(`)_            \"By blood a king,    "
		 << "\n\t\t              //`\\/ |\\ 0`\\\\           in heart a clown.\"  "
		 << "\n\t\t              ||-.\\_|_/.-||          ~Alfred Lord Tennyson"
		 << "\n\t\t              )/ |_____| \\(    _ "
		 << "\n\t\t             0   #/\\ /\\#  0   (_) "
		 << "\n\t\t                _| o o |_ "
		 << "\n\t\t         _     ((|, ^ ,|)) "
	 	 << "\n\t\t        (_)     `||\\_/||` "
	 	 << "\n\t\t                 || _ ||      _ "
		 << "\n\t\t                 | \\_/ |     (_) "
	 	 << "\n\t\t             0.__.\\   /.__.0 "
		 << "\n\t\t              `._  `\"`  _.' "
		 << "\n\t\t       kkr       / ;  \\ \\ "
		 << "\n\t\t               0'-' )/`'-0 "
		 << "\n\t\t                   0` "
		 << "\n\n\n";

	system("PAUSE");
}	
	
void welcome()
{
	system("CLS");
	cout << "\n\n\n";	
	cout << "\n\t/--------------------------------------------------------------\\";
	cout << "\n\t|                      About This Program                      |";
	cout << "\n\t+--------------------------------------------------------------+";
	cout << "\n\t|                                                              |";
	cout << "\n\t|                                                              |";
	cout << "\n\t|             Programmer's Name: Kris Rossman                  |";
	cout << "\n\t|                          Date: "myDate                      "|";        
	cout << "\n\t|               Name of program: "myActivity                  "|";
	cout << "\n\t|                                                              |";
	cout << "\n\t|    /-------------------- Description --------------------\\   |";
	cout << "\n\t|    | "   line1                                         " |   |";
	cout << "\n\t|    | "           line2                                 " |   |";
	cout << "\n\t|    | "                         line3                   " |   |";
	cout << "\n\t|    \\-----------------------------------------------------/   |";
	cout << "\n\t|                                                              |";
	cout << "\n\t|                                                              |";
	cout << "\n\t|                                                              |";
	cout << "\n\t\\--------------------------------------------------------------/";
	cout << "\n\n\n";
	system("PAUSE");
}
Line 70: don't loop on EOF

70
71
72
73
74
		while (infile >> score)
		{

			if (score >= 0 && score <= 100)
			{

This is probably killing your average, so that grade gets past all the if..elses without being assigned a value. Since the value it has is random, you might see anything in the output.

111
112
113
114
115
116
117
118
119
120
	if (num >= A)
		grade = 'A';
	else if (num >= B)
		grade = 'B';
	else if (num >= C)
		grade = 'C';
	else if (num >= D)
		grade = 'D';
	else // if (grade < D), student fails, right?
		grade = 'F';


To get the lowest score, you'll need another variable, like int lowest_score = 100;. While you read the scores in from file, check to see if score is less than lowest_score. If it is, you'll need to update the lowest score's value.

Hope this helps.
Topic archived. No new replies allowed.