class_CallMemberFunction

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.

code as follows:

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
//
// CallMemberFunction- define and invoke a function
//                     that's a member of the class student
//
#include<cstdio>
#include<cstdlib>
#include<iostream>
using namespace 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;
}
You have spelled float as flout.
ok now i feel like an idiot i cant believe i overlooked that!
thank you.
Topic archived. No new replies allowed.