Ok there are two functions. The first function(userinput) ask the user to input two values. The second function has a formula and uses the first functions inputs to calculate and return a floating point number. Now I called the second function in main and everything works, even used a calculator to verify that the formula works.
My professor on the other hand said I wrote my functions incorrectly and I am scratching my head thinking if its written incorrectly, why does it work like I want it to? SO please are my functions written incorrectly and can it be written better? If so please post it. Thank you.
[code]
#include <iostream>
#include <cmath>
usingnamespace std;
void userinput(float& x, float& y); //function declarations
float windchillcalculate(float windchill);
int main(){
float a=0;
windchillcalculate(a); //calls the calculated function
return 0;
}
void userinput(float& x, float& y){ //1st function ask user for input
cout << "Please enter the wind speed in miles per hour: ";
cin >> x;
cout << "Please enter the temperature in degrees farenheight: ";
cin >> y;
}
float windchillcalculate(float windchill){ //second function calls 1st function an uses its values to calculate and return windchill
float x = 0,y = 0;
userinput(x,y);
windchill = 35.74 + .6215*y - 35.75*pow(x, .16) + .4275*y*pow(x, .16);
cout << "The wind chill factor is: " << windchill;
return windchill;
}
#include <iostream>
#include <cmath>
usingnamespace std;
void userinput(float& x, float& y); //function declarations
float windchillcalculate(float a, float b);
int main(){
float c = 0,d=0;
userinput(c, d);
cout << "The wind chill factor is: " << windchillcalculate(c, d); //calls the calculated function
return 0;
}
void userinput(float& x, float& y){ //1st function ask user for input
cout << "Please enter the wind speed in miles per hour: ";
cin >> x;
cout << "Please enter the temperature in degrees farenheight: ";
cin >> y;
}
float windchillcalculate(float a, float b){ //second function calls 1st function an uses its values to calculate and return windchill
float windchill;
windchill = 35.74 + .6215*b - 35.75*pow(a, .16) + .4275*b*pow(a, .16);
return windchill;
}