hello, i am getting an error message saying that the float is not declared in line 14. tho this program is from a book that i am studying i have tried to figure it out my self and can not come up with a solution.
//
// CallMemberFunction- define and invoke a function
// that's a member of the class student
//
#include<cstdio>
#include<cstdlib>
#include<iostream>
usingnamespace std;
class Student
{
public:
// add a completed course to the record
float addCourse(int hours, flout grade)
{
// calculate the sum of all courses times
// the average grade
float weightedGPA;
weightedGPA = semesterHours * gpa;
// now add in the new course
semesterHours += hours;
weightedGPA += grade * hours;
gpa = weightedGPA / semesterHours;
// return the new gpa
return gpa;
}
int semesterHours;
float gpa;
};
int main()
{
//create a student object and initialize it
Student s;
s.semesterHours = 3;
s.gpa = 3.0;
// the values before the call
cout << "Before: s = (" << s.semesterHours
<< ", " << s.gpa
<< ")" << endl;
// the following subjects the data members of the s
// object to the member function addCourse()
cout << "Adding 3 hours with a grade of 4.0" << endl;
s.addCourse(3, 4.0); // call the member function
// the values are now changed
cout << "After: s = (" << s.semesterHours
<< ", " << s.gpa
<< ")" << endl;
cout << "\n\n";
system("PAUSE");
return 0;
}