Ok i fixed most of all of the warnings...now i'm getting this one small warning where line 61 is not being initialized..I can't seem to find the problem of initializing those..Maybe if this is fixed..the output would come out correct...guidance please?
here's the warning: c:\users\tommeh\desktop\program 5\program 5\main.cpp(61): warning C4700: uninitialized local variable 'stud' used
I tried initializing stud.ID and stud.gpa like this
stud.ID=0;
stud.gpa=0;
i initialized those two in while loop along with the other variables that are initialized, but in the output i got all 0's in the ID and -1.$ in the gpa.
If you want it to be initialised, you have to define a constructor for your struct in which you initialise the variables:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
struct Student
{
int ID;
double points;
double hours;
double gpa;
Student()
{
//this function is called each time the a Student object is created
points = 0;
hours = 0;
gpa = 0;
ID = 0;
}
};
BTW, use classes rather than structures. struct is the obsolete form for class in C. You're programming C++, so you better go with class. The only difference is that the access type for struct is public, while it's private in classes. So at the beginning of your class add
public:
and you should have exactly the same functionality, but with up to date style.
BTW, use classes rather than structures. struct is the obsolete form for class in C. You're programming C++, so you better go with class. The only difference is that the access type for struct is public, while it's private in classes. So at the beginning of your class add
public:
and you should have exactly the same functionality, but with up to date style.
Or throw some nice OOP principles (namely encapsulation) in there. Private member variables, public setter/getter methods.
can't use classes, our professor only want us to use what we learned already and that just data structures....
Ok the variables are initialized, but now, when i run the program, its only reading 1 ID number, and the GPA is still 1.$
The code looks much better, and the output file is coming out almost right, but i'm still having a problem with the gpa's output: its all still coming out like -1.$.
does it have something to do with the variables, double grade, ch;??
because they are in the function prototype findPoints(double grade, double ch)
and stud.points is in the function definition, which the variable "points" is in the data structure
My professor ONLY wanted the variables gpa, points, hours, and ID to be in the structure, leaving the other variables "grade" and "ch" out.
I'm not exactlu sure what sort of function the OP is truing to make - and I don't want towaste time guessing - so maybe if he give us a better explanation
of what he is trying to do then we will be able to help.