Why is my Average 0?

Hello, I've been trying to create my functions and calculate the lowest score from the 6 test scores of each student so I can then drop the lowest score and find the average but my average is coming out to zero! This program displays a menu then select a choice but to proceed I need to fix this issue! please help.. I've been trying..sample input file ' (removed menu functions to be able to post topic)
Intro To Computer Science c++
SAL 343
JHG 344
John Adams
111223333 100 87 93 90 90 89 91 
Willy Smith
222114444 90 73 67 77 70 80 90 
Phil Jordan
777886666 100 80 70 -50 60 90 100


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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
#include <iostream>
#include <string>
#include<fstream>
#include <iomanip>
#define CAP 25
using namespace std ;

struct Student{
    string  Course_Name,Course_Id, Course_Location;
	string	FirstName, LastName;
	float	Quiz, Test[6], Average;
    int Id;
    char Grade;
    
} ;
bool Open_File(ofstream &fout);
float Find_Lowest(Student List[], float&Min);
bool Open_File(ifstream &fin);
void Read_Student(Student & Temp, ifstream & fin);
int Read_list(Student List[], int Max_Size);
void Print_List(Student & Temp, Student List[], int Size);
float calcAverage(Student List[],float Min);
void Print_Course(Student List[],ofstream&fout, int Size);
int Search(Student List[], int Size, string Target);
void LookUp_Student(Student List[], int Size);
void Menu();
void Process_Menu(Student List[], int Size, float Min);
void Print_Student(Student & Temp);
void Print_Search(Student Temp);
Student Read_Student();
Student Process_Grade(Student & Temp, Student List[], float Min, int Size);
char Grade_it(Student List[], Student & Temp);
int main()
{
    
    ifstream fout;
    float Min=0;
    Student Temp;
    Student stu[CAP];
    int		Logical_Size = 0 ;
    Logical_Size = Read_list(stu,CAP);
	if (Logical_Size > 0 ){
        Process_Menu(stu,Logical_Size,Min);
	}
	else
		cout << "Empty file\n\n";
	return 0 ;
    
    
}



int Search(Student List[], int Size, string Target){
    for(int i = 0 ; i < Size ; i++)
        if (Target == List[i].LastName)
            return i;
    return -1;
}

void LookUp_Student(Student List[], int Size){
    string Target;
    int Index;
    cout << "\nEnter a name to search for (Last Name e.g. Smith):  ";
    getline(cin,Target);
    Index = Search(List,Size,Target);
    if (Index == -1)
        cout << Target <<" is not on the list.\n" ;
    else
        Print_Search(List[Index]);
}
void Read_Student(Student & Temp , ifstream & fin){
    
    fin >> Temp.FirstName;
    fin >> Temp.LastName;
    fin >> Temp.Id;
    fin >> Temp.Quiz;
    for (int i = 0 ; i < 6 ; i++)
        fin >> Temp.Test[i];
}

int Read_list(Student List[], int Max_Size)
{
    Student Temp;
	ifstream fin;
	int		i = 0;
    
	if (Open_File(fin))
	{
        
        getline(fin, List[i].Course_Name);
        getline(fin, List[i].Course_Id);
        getline(fin, List[i].Course_Location);
        Read_Student(List[i],fin);
		while(!fin.eof())
		{
			i++ ;
			if (i == Max_Size){
				cout << "\nArray is full.\n" ;
				break;
			}
            Read_Student(List[i],fin);
		}
        
	}
	else
	{
		cout <<"\nBad file. Did not open. Program terminated.\n";
		exit(0);
	}
	return (i);
}


void Print_List(Student & Temp, Student List[], int Size){
    
   	cout <<left << fixed << setprecision(2) <<showpoint <<endl ;
	cout << setw(19) << "Name" << setw(18) << "ID" << setw(18) << "Average" << setw(16)
    << "Grade" << endl;
    cout << "=============================================================" << endl;
    
    for(int i = 0; i < Size;i++)
        
        cout << setw(19) << List[i].LastName +", "+ List[i].FirstName << setw(18) << List[i].Id << setw(20) << List[i].Average << List[i].Grade << endl;
    
    
}

void Print_Course(Student List[],ofstream&fout, int Size){
    int i =0;
    fout << "Course Name: " << List[i].Course_Name << endl;
    fout << "Course ID:  " << List[i].Course_Id << endl;
    fout << "Course Location: " << List[i].Course_Location << endl;
    
	fout <<left << fixed << setprecision(2) <<showpoint <<endl ;
	fout << setw(19) << "Name" << setw(18) << "ID" << setw(18) << "Average" << setw(16)
    << "Grade" << endl;
    fout << "=============================================================" << endl;
    
    for(int i = 0; i < Size;i++)
        
        fout << setw(19) << List[i].LastName +", "+ List[i].FirstName << setw(18) << List[i].Id << setw(20) << List[i].Average << List[i].Grade << endl;
    
    fout.close();
}

float Find_Lowest(Student List[], float&Min)
{
    Student Temp;
    Min = Temp.Test[0];
    for(int i = 0; i < 6; i++)
    {
        if (Temp.Test[i] > Min)
        {
            Min = Temp.Test[i];
        }
    }
    return (Min);
}

float calcAverage(Student List[],float Min)

{
    Student Temp;
    float Total = 0;
    for(int i = 0; i < 6; i++)
    {
        Total+=Temp.Test[i];
    }
    Temp.Average = Total + Temp.Quiz;
    return(Temp.Average);
}

char Grade_it(Student List[], Student & Temp)
{
    float Min = 0;
    calcAverage(List,Min);
    Min = Find_Lowest(List,Min);
    
    if (Temp.Average >= 0 && Temp.Average <= 59.9)
    {
        Temp.Grade = 'F';
    }
    else if (Temp.Average >= 60 && Temp.Average <= 69.9)
    {
        Temp.Grade = 'D';
    }
    else if (Temp.Average >= 70 && Temp.Average <= 79.9)
    {
        Temp.Grade = 'C';
    }
    else if (Temp.Average >= 80 && Temp.Average <= 89.9)
    {
        Temp.Grade = 'B';
    }
    else if (Temp.Average >= 90 && Temp.Average <= 100)
    {
        Temp.Grade = 'A';
    }
    
    return (Temp.Grade);
}

bool Open_File(ifstream &fin)
{
	string    File_Name;
	cout <<"Enter file name: ";
	getline(cin, File_Name);
	fin.open(File_Name.c_str());
	if(fin.fail())
		return false ;
	else
		return true ;
}

bool Open_File(ofstream &fout)
{
	string    File_Name;
	cout <<"Enter file name: ";
	getline(cin, File_Name);
	fout.open(File_Name.c_str());
	if(fout.fail())
		return false ;
	else
		return true ;
}
void Print_Student(Student & Temp){
    
    cout << endl;
    cout << "Here is the student data you entered: " << endl;
    cout << "Name: " << Temp.FirstName << ", " << Temp.LastName << endl;
    cout << "ID Number: " << Temp.Id << endl;
    cout << "Grades for Quiz and Six Test scores " << endl;
    cout << "Quiz Score: " << Temp.Quiz << endl;
    for (int i=0; i < 6; i++)
    {
        cout << setw(7) << " Test Score # " << i+1 << ": " << Temp.Test[i] << " " << endl;
    }
    
	cin.ignore(10,'\n');
}

void Print_Search(Student Temp){
    cout << left << fixed << setprecision(2) << showpoint;
    cout << setw(20) << "\nName:  "  << Temp.FirstName << " " << Temp.LastName   << endl;
    cout << setw(20) << "ID:  "      << Temp.Id           << endl;
    cout << setw(20) << "Average:  " << Temp.Average      << endl;
    cout << setw(20) << "Grade:  "   << Temp.Grade << endl;
}

Student Read_Student(){
	Student	Temp ;
    cout << "Enter the following student data:" << endl;
	cout <<"Student Name(e.g. Bob Smith): " ;
	cin >> Temp.FirstName >> Temp.LastName;
	cout <<"Student ID Number(without dashes): ";
    cin >> Temp.Id;
    cout << "Student Quiz Score: ";
    cin >> Temp.Quiz;
    if(Temp.Quiz < 0 || Temp.Quiz > 100)
    {
        cout << "Enter a valid quiz score between 0 to 100 for"
        << "\nQuiz Score: ";
        cin >> Temp.Quiz;
    }
    cout << setw(20) <<"Scores for Six Tests:" << endl ;
	for (int i = 0 ; i < 6 ; i++)
    {
		cout <<setw(7)<< "Test # " << i+1 << ": " ;
        cin >> Temp.Test[i];
        while (Temp.Test[i] < 0 || Temp.Test[i] > 100)
        {
            cout << "Enter a valid test score between 0 to 100 for"
                 << "\nTest # " << i+1 << ": ";
            cin >> Temp.Test[i];
        }
    }
	return Temp ;
}

    
}


This is how my output is(for printing only), it doesn't find the average and always prints zero:
Enter file name: /Users/MJ/Desktop/final.txt

Name               ID                Average           Grade           
=============================================================
Adams, John        111223333         0.00                \377
Smith, Willy       222114444         0.00                
Jordan, Phil       777886666         0.00                
Last edited on
please help
In float calcAverage(Student List[],float Min) you pass in List but don't use it. And in the calculation you are using Student Temp; which is never set, so it might be all zeros giving you your Average of zero. Try using Student List[] in the for loop.
It still didn't work when I did that.. any other suggestions? I have been trying forever
1
2
3
4
5
6
char Grade_it(Student List[], Student & Temp)
{
    float Min = 0;
    calcAverage(List,Min);
    Min = Find_Lowest(List,Min);
//... 


calcAverage() returns a float, and you're not even using it.
closed account (E3Uiz8AR)
It's only my 2 cents, but have you considered looking into classes?

I understand it's an intro, but reading up on classes might make this easier for you to write, read, edit and debug.

They aren't as scary as I first thought either!

Hope it helps, even a little!
Look at what I did and make it fit into you code.
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
#include <iostream>
#include <string>
#include<fstream>
#include <iomanip>
#define CAP 25
using namespace std ;

struct Student{
    string  Course_Name,Course_Id, Course_Location;
	string	FirstName, LastName;
	float	Quiz, Test[6], Average;
    int Id;
    char Grade;
    
} ;
void Read_Student(Student & Temp, ifstream & fin);
int Read_list(Student List[], int Max_Size);
//void Print_List(Student & Temp, Student List[], int Size);
void Print_List(Student List[], int Size);
//float calcAverage(Student List[],float Min);
void calcAverage(Student List[],float Size);
Student Read_Student();
//char Grade_it(Student List[], Student & Temp);
char Grade_it(Student & Temp);

int main() {
   ifstream fout;
   float Min=0;
   Student Temp;
   Student stu[CAP];
   int		Logical_Size = 0 ;
   Logical_Size = Read_list(stu,CAP);
   if (Logical_Size > 0 ){
      for (int i(0); i< Logical_Size;i++){
         Grade_it(stu[i]);
      }
      Print_List(stu,Logical_Size);
   }
   else
      cout << "Empty file\n\n";
   return 0 ;
}

void Read_Student(Student & Temp , ifstream & fin){
    fin >> Temp.FirstName;
    fin >> Temp.LastName;
    fin >> Temp.Id;
    fin >> Temp.Quiz;
    for (int i = 0 ; i < 6 ; i++)
        fin >> Temp.Test[i];
}

int Read_list(Student List[], int Max_Size) {
   Student Temp;
   ifstream fin("mjyz.txt");
   int		i = 0;
    
   if (fin.is_open()) {
   
      getline(fin, List[i].Course_Name);
      getline(fin, List[i].Course_Id);
      getline(fin, List[i].Course_Location);
      Read_Student(List[i],fin);
      while(!fin.eof()) {
         i++ ;
         if (i == Max_Size){
            cout << "\nArray is full.\n" ;
            break;
         }
         Read_Student(List[i],fin);
      }
   }
   else {
      cout <<"\nBad file. Did not open. Program terminated.\n";
      exit(0);
   }
   return (i);
}

//void Print_List(Student & Temp, Student List[], int Size){
void Print_List(Student List[], int Size){
   cout <<left << fixed << setprecision(2) <<showpoint <<endl ;
   cout << setw(19) << "Name" << setw(18) << "ID" << setw(18) << "Average" << setw(16)
         << "Grade" << endl;
   cout << "=============================================================" << endl;

   for(int i = 0; i < Size;i++)
      cout << setw(19) << List[i].LastName +", "+ List[i].FirstName 
           << setw(18) << List[i].Id << setw(20) << List[i].Average 
           << List[i].Grade << endl;
}

float calcAverage(Student &Temp,float &Min) {
    float Total = 0;
    for(int i = 0; i < 6; i++) {
        Total+=Temp.Test[i];
    }

//*******************************************
//    You should fix the hardcode 7 below
//*******************************************

    Temp.Average = (Total + Temp.Quiz)/7.0;
    return(Temp.Average);
}

char Grade_it(Student & Temp) {
    float Min = 0;
    calcAverage(Temp,Min);
    //Min = Find_Lowest(List,Min);
    
    if (Temp.Average >= 0 && Temp.Average <= 59.9) {
        Temp.Grade = 'F';
    } else if (Temp.Average >= 60 && Temp.Average <= 69.9) {
        Temp.Grade = 'D';
    } else if (Temp.Average >= 70 && Temp.Average <= 79.9) {
        Temp.Grade = 'C';
    } else if (Temp.Average >= 80 && Temp.Average <= 89.9) {
        Temp.Grade = 'B';
    } else if (Temp.Average >= 90 && Temp.Average <= 100) {
        Temp.Grade = 'A';
    }
    
    return (Temp.Grade);
}

Name               ID                Average           Grade           
=============================================================
Adams, John        111223333         91.43               A
Smith, Willy       222114444         78.14               C
Jordan, Phil       777886666         64.29               D
Thank you guys!
Topic archived. No new replies allowed.