couple of errors

Hi guys, I am writing a code to add two movies give them ratings (i.e. 1-5) and their rating (i.e. G, PG, PG-13, R) and output the average rating and rated of the movie but I have two errors that i dont know how to fix they are:
47 and at 60 error: cannot convert 'movie::findAverage' from type 'double (movie::)()' to type 'double'
and
70:29: error: invalid use of incomplete type 'class myMovie'
27:23: error: forward declaration of 'class myMovie'

Here is the code:

#include <iostream>
#include <string>
using namespace std;

class movie{
public:
string name;
string rating;
int terrible;
int bad;
int ok;
int good;
int great;
void addRating(void);
double findAverage(void);
movie(){
terrible = 0;
bad = 0;
ok = 0;
good = 0;
great = 0;
}


};

void addRating (class myMovie, int& rating);
void findAverage(class myMovie, double& average);

int main() {
// Variable Declarations
movie myMovie1, myMovie2;
int n1, n2, i;
double average1, average2;

// First Movie
cout << "What is the name of your first movie? " << endl;
cin >> myMovie1.name;
// assign myMovie a rating
cout << "What is the rating of the movie? " << endl;
cin >> myMovie1.rating;
// functions
cout << "How many Ratings do you have? " << endl;
cin >> n1;
for (i=0; i < n1; i++)
myMovie1.addRating();
average1= myMovie2.findAverage;

// Second Movie
cout << "What is the name of your second movie? " << endl;
cin >> myMovie2.name;
// assign myMovie a rating
cout << "What is the rating of the movie? " << endl;
cin >> myMovie2.rating;
// functions
cout << "How many Ratings do you have? " << endl;
cin >> n2;
for (i=0; i < n2; i++)
myMovie2.addRating() ;
average2= myMovie2.findAverage;

// output
cout << "The movie " << myMovie1.name << " is rated " << myMovie1.rating << endl;
cout << "it's average rating is " << average1 << endl;
cout <<"The movie " << myMovie2.name << " is rated " << myMovie2.rating << endl;
cout << "it's average rating is " << average2 << endl;
}


void myMovie::addRating(void){
// read a single rating value (1-5)
int rating
cout << "What would you rate the movie? (i.e. 1-5) " << endl;
cin >> rating;
// increment the appropriate myMovie rating counter
if (rating == 1)
myMovie.terrible++;
else if (rating == 2)
myMovie.bad++;
else if (rating == 3)
myMovie.ok++;
else if (rating == 4)
myMovie.good++;
else if (rating == 5)
myMovie.great++;
else
cout << "Try Again: " << endl
cin >> rating
}

double myMovie::findAverage(void){
return ((1 * myMovie.terrible) + (2 * myMovie.bad) + (3 * myMovie.ok) + (4 * myMovie.good) + (5 * myMovie.great)) / 5;
}
The class is named movie.

Function double myMovie::findAverage(void){
should be
1
2
3
4
double movie::findAverage(void)
{
    return ((1 * terrible) + (2 * bad) + (3 * ok) + (4 * good) + (5 * great)) / 5;
}


Similarly with myMovie::addRating

In main()
 
average1= myMovie1.findAverage;

should call the function,
like this:
 
double average1 = myMovie2.findAverage();  // note the parentheses () 

Note - it's better to define the variable double average1 at the point where you have a suitable value to give it, instead of defining it at the start and leaving it with no particular initial value. Same with average2


Also, there is a lot of repetition in the code. Consider either using a loop, or making a separate function to contain the code just once, then call it as many times as needed.

Last edited on
Line 26,27: You're declaring these functions as global, but you have no global implementation of these functions. You've declared them as member functions. Get rid of these two lines.

Line 45,58: Function calls require ().

Line 65,86: class name is movie, not mymovie.

Line 70,80,82: needs a ;

Line 72,74,,76,78,80,87: member variables do not need to be qualified by the class name.

Line 85: If the rating is input on the second attempt, you don't edit check it. Nor does the rating get computed.

PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.



Topic archived. No new replies allowed.