calling function seems dosent work. pls help

Dec 25, 2011 at 9:01am
hey guys how are u today?
btw my program seem to have lil prob.
my function determineLevel seems cant be called.
it give undeclared error.
anyone have idea?
thank u in advance and merry Christmas!

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
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

class Movie
{
    string title;
    int year;
    float rate;

    public :
    void set_movie(string t, int y)
    {
        title = t;
        year = y;
    }
    friend class Person;

    friend void determineLevel(Movie);
};

class Person
{
    string name;

    public:

    Person()
    {
        cout << "-------WELCOME-------" << endl;
    }

    void rate(Movie r)
    {
        cout << "please rate this movie (" << r.title << ") (1-10)  : ";
        cin >> r.rate;
        determineLevel();
    }

    void setName(string n)
    {
        name = n;
    }

    string getName()
    {
        return name;
    }
};

void determineLevel(Movie r)
{
    if (r.rate >= 8 && r.rate <= 10)
        cout << "You've rated this movie as excellent" << endl;
    else if (r.rate>= 6 && r.rate<= 7)
        cout << "You've rated this movie as good" << endl;
    else if (r.rate>= 4 && r.rate<= 5)
        cout << "You've rated this movie as fair" << endl;
    else if (r.rate>= 0 && r.rate<= 3)
        cout << "You've rated this movie as poor" << endl;
    else
        cout << "out of range" << endl;
}

int main()
{
    Movie mov1;
    Movie mov2;
    Person p;

    string name_main;
    char choice_cont;
    int choice;

    mov1.set_movie("Tangled", 2009);
    mov2.set_movie("Kung Fu Panda", 2005);

    cout << "To quit(enter Q or q), To continue (enter anything): ";
    cin >> choice_cont;
    cin.ignore();

    while (choice_cont != 'Q' && choice_cont != 'q')
    {
            cout << "enter name : ";
            getline(cin,name_main);

            p.setName(name_main);

            cout << "-----------------------" << endl;
            cout << "     Rate a movie      " << endl;
            cout << "-----------------------" << endl;
            cout << "[1] Tangled            " << endl;
            cout << "[2] Kung Fu Panda      " << endl;
            cout << "-----------------------" << endl;

            cout << "enter movie choice : ";
            cin >> choice;

            switch (choice)
            {
                case 1 :
                        p.rate(mov1);
                        break;

                case 2 :
                        p.rate(mov2);
                        break;
                default :
                        cout << "invalid input" << endl;
            }

    cout << "thank you " << p.getName() << endl;
    cout << "To quit(enter Q or q), To continue (enter anything): ";
    cin >> choice_cont;
    cin.ignore();
    }
    return 0;
Dec 25, 2011 at 10:55am
I'd like to draw your attention to line 38: you don't pass in a parameter, do you?
Parameter list is a part of a function's signature. Be sure to get it right.

Also, if all of the codes are in one single file, I doubt it will work even if you correct the mistake above.
In Python, before you use something, you always need to make sure that you've already declared it (or have already defined it).
Check your code again.
Dec 25, 2011 at 11:06am
thanks u for pointing that out.
yes i have re-write my code but the problem remain the same.
here my code.
1
2
3
4
5
6
    void rate(Movie r)
    {
        cout << "please rate this movie (" << r.title << ") (1-10)  : ";
        cin >> r.rate;
        determineLevel(r.rate);
    }


and yes and i have declared the function at line 20, as a friend of class movie.
friend void determineLevel(Movie);
Dec 25, 2011 at 2:56pm
According to your function prototype, it should be:
1
2
3
4
5
6
void rate(Movie r)
    {
        cout << "please rate this movie (" << r.title << ") (1-10)  : ";
        cin >> r.rate;
        determineLevel(r);
    }


And you're otherwise good to go.
Dec 25, 2011 at 2:58pm
i think you have to declare
class Person

imediatly after using namespace std ;
Dec 25, 2011 at 4:32pm
^ Please explain.

friend void determineLevel(Movie); That it is not a function declaration.
Dec 25, 2011 at 9:16pm
Before Movie class you need to write this:
void determineLevel(Movie);
Dec 25, 2011 at 10:21pm
after line 118 add "}"
also try
1
2
3
4
5
6
    void rate(Movie r)
    {
        cout << "please rate this movie (" << r.title << ") (1-10)  : ";
        cin >> r.rate;
        determineLevel(r);
    }



r.rate is a float value and the function you created needs a "Movie" instance as parameter

I tried the code with those changes and it worked :)
Dec 25, 2011 at 10:23pm
thanks a lot it should be
1
2
3
4
5
6
void rate(Movie r)
    {
        cout << "please rate this movie (" << r.title << ") (1-10)  : ";
        cin >> r.rate;
        determineLevel(r);
    }

thanks a lot guys for helping me!
you guys just made my day.
have a great day and merry Christmas!!
Topic archived. No new replies allowed.