Mar 23, 2013 at 7:42pm UTC
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?
Mar 23, 2013 at 8:24pm UTC
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 Mar 23, 2013 at 8:25pm UTC
Mar 23, 2013 at 8:30pm UTC
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
Mar 23, 2013 at 8:42pm UTC
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.)
Mar 23, 2013 at 9:49pm UTC
calcWattsGenerated(double , double )
It's another function which has no body.
Mar 24, 2013 at 2:23am UTC
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.
Mar 24, 2013 at 1:27pm UTC
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 Mar 24, 2013 at 1:27pm UTC
Mar 24, 2013 at 5:48pm UTC
It just compiled. thanks for all the help