Weird problem

My program compiles and runs...

-but-

There is a function that takes grade data from a file, averages the scores, and puts the resulting number in a vector. When you select the option to display the information, all students come up with 0 (zero) averages for their final scores the FIRST time. If you select the display scores option again, the information is there with the proper averages.

I can't see how this can happen and any advice would be appreciated.

Here's the code that I -think- contains the problem (that I apparently can't see):

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
#ifndef GROUPOFSTUDENTS_H_
#define GROUPOFSTUDENTS_H_

#include <vector>
#include <iostream>
#include "StudentCourses.h"

class GroupOfStudents
{
private:
	vector<StudentCourses> stc_vec;

public:
	GroupOfStudents() {};
	GroupOfStudents(const vector<StudentCourses>& v) :
		stc_vec(v) {};

	const vector<StudentCourses>& get_student_courses() const
		{ return stc_vec; }
	void display() ;
	void display_highest();
	void calc_all();
};

void GroupOfStudents::display() {
	
	for(unsigned int i=0;i<stc_vec.size();++i) {
		stc_vec[i].display();
		
	};
	return;
};

void GroupOfStudents::display_highest() {
	unsigned int i;
	double max=0;
	vector<double> v1(stc_vec.size());
	for(i=0;i<v1.size();++i) {
		v1[i] = stc_vec[i].get_final_score();
		if(v1[i]>max) max=v1[i];
	}
	for(i=0;i<v1.size();++i) {
		if(v1[i] == max) stc_vec[i].display();
	}
	return;
};

void GroupOfStudents::calc_all() {
	for(unsigned int i=0;i<stc_vec.size();++i) {
		stc_vec[i].courses.calc_final_score();
		stc_vec[i].courses.calc_letter_grade();
	};
	return;
};
#endif /*GROUPOFSTUDENTS_H_*/



There is a GroupOfStudents object in the menu program that references this class. Essentially, you press 3, you get the students' info. Only you have to press 3 twice. ???

Thanks,

-KA
Last edited on
You'll have to post more of your code.
Topic archived. No new replies allowed.