Error with compiling program with fuctions.

i am writing a code, but i am having some problems with a fuction.
this is the fuction:

void printWattsGenerated( double watts )
{
if( watts < 1000 )
{
cout << "Your windmill generated " << watts << "watts today.\n";
}
else if( watts < 1,000,000 )
{
cout << "Your windmill generated " << watts / 1000 << "kilowatts today.\n";
}
else
cout << "Your windmill generated " << watts / 1,000,000 << "megawatts today.\n";
}

When i compile, I get this error message:
lab4.cpp: In function 'void printWattsGenerated(double)':
lab4.cpp:189: error: invalid operands of types 'int' and 'const char [18]' to binary 'operator<<'

I do not know how to fix it. Any ideas?
1
2
3
4
5
6
7
8
9
10
11
12
13
void printWattsGenerated( double watts )
{
    if( watts < 1000 )
    {
        cout << "Your windmill generated " << watts << "watts today.\n";
    }
    else if( watts < 1,000,000 )
    {
        cout << "Your windmill generated " << (watts / 1000) << "kilowatts today.\n";
    }
    else
        cout << "Your windmill generated " << (watts / 1000000) << "megawatts today.\n";
}


Not the added parentheses and the removal of commas from "1,000,000" which would've been equivalent to: (watts/0) thanks to the comma operator.

[Edit: Why is this in the UNIX/Linux Programming forum?]
Last edited on
ok i fixed that but i got another error message:
/tmp/ccfzm1jf.o: In function `main':
lab4.cpp:(.text+0x8d): undefined reference to `calcWattsGenerated(double, double)'
collect2: ld returned 1 exit status
Define the function?

If it's already defined, make sure the generated object code is being linked against. (If you're using an IDE, make sure the source file in which it is defined is actually in the project.)
calcWattsGenerated(double, double)
It's another function which has no body.
this is the function:
double calcWattsGenerated( double maxWatts, double windSpeed, double watts )
{
if( windSpeed <= 28 )
{
watts = maxWatts * pow( windSpeed / 28.0, 3.0 );
}
else
{
watts = maxWatts;
}
return watts;
}
I still dont understand how to fix it.
lab4.cpp:(.text+0x8d): undefined reference to `calcWattsGenerated(double, double)'


double calcWattsGenerated( double maxWatts, double windSpeed, double watts )

Do the parameters look like they match up to you?
For a thing like the one you wanted:

1
2
3
4
5
6
7
8
9
10
11
12
13
double calcWattsGenerated( double maxWatts, double windSpeed )
{
    double watts = 0.0;
    if( windSpeed <= 28.0 )
    {
        watts = maxWatts * pow( windSpeed / 28.0, 3.0 );
    }
    else
    {
        watts = maxWatts;
    }
    return watts;
}
Last edited on
It just compiled. thanks for all the help
Topic archived. No new replies allowed.