Need help with a function error *solved*

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

double theWindChill(double windSpeed, double tempC);
//calculates wind chill using wind speed and the temperature in degrees celcius


float currentWindChill;

int main()
{

double WindSpeed;
double TempC;


cout << "What is the current wind speed?\n";
cin >> WindSpeed;

cout << "What is the current temperature in degrees Celcius?\n";
cin >> TempC;

if (TempC <= 10)
{
currentWindChill = theWindChill(double windSpeed, double tempC);

cout << "The current wind chill is " << currentWindChill;
}

else
{
cout << "--temperature violates standard--";
}


return 0;
}

double theWindChill(double windSpeed, double tempC)
{


return (33-(((10 * sqrt(windSpeed) - windSpeed + 10.5)(33-tempC))/(23.1)));
}


this is the code. user inputs wind speed and temperature and then the function should calculate the wind chill.. i get these errors. can't figure out what to do about them.

homeworkchp3prb7.cpp: In function ‘int main()’:
homeworkchp3prb7.cpp:26: error: expected primary-expression before ‘double’
homeworkchp3prb7.cpp:26: error: expected primary-expression before ‘double’
homeworkchp3prb7.cpp: In function ‘double theWindChill(double, double)’:
homeworkchp3prb7.cpp:44: error: ‘(((sqrt(windSpeed) * 1.0e+1) - windSpeed) + 1.05e+1)’ cannot be used as a function

Last edited on
Instead of

currentWindChill = theWindChill(double windSpeed, double tempC);

write

currentWindChill = theWindChill(windSpeed, tempC);
currentWindChill = theWindChill(double windSpeed, double tempC);

When calling a function, you don't specify the type of the parameter. You only do that when defining the function. But when calling it, you just give it the parameters you want.

Here, you probably wanted to give it your local variables 'WindSpeed' and 'TempC' (note: the capitalized versions as defined in main).

currentWindChill = theWindChill(WindSpeed, TempC);

As for your last error:

1
2
3
(10 * sqrt(windSpeed) - windSpeed + 10.5)(33-tempC)
                                        ^^
                                        ||


I don't know what you're trying to do there, but it looks like you're missing an operator. If you were trying to multiply those 2 values together, you need to use the * operator. Back-to-back parenthesis does not mean multiplication in C++ like it does in algebra.

(10 * sqrt(windSpeed) - windSpeed + 10.5) * (33-tempC)


EDIT: dammit again vlad! XD
Last edited on
Thank you guys very much. For the last error; that is what was missing.. didn't realize algebraic syntax didn't work.
@Disch
EDIT: dammit again vlad! XD


But you answer is more complete because I did not even look through all the source code and stopped when found the invalid function call.




Last edited on
Topic archived. No new replies allowed.