## remedial C++

I know I am not a moron but this C++ is killing me, I have to write a program using functions to convert temp between c, f, k I am hung up

// Mod4project2tempconvert.cpp : Defines the entry point for the console application.
#include <iostream>
using namespace std;

double ftemp (double F, double C, double K, double temp, double scale)

{
while (scale != 0)
{
if (scale==C);
F=temp*9/5+32;
K=temp+273.15;

if (scale==F);
C=(temp-32)*5/9;
K=(temp-32)*5/9+273.15;

if (scale==K);
F=(temp-273.15)*9/5+32;
C=temp-273.15;
}
}

int main()
{
double F, C, K, temp, scale;
cout<<"Enter the scale you want to convert from C, F, or K- 0 to quit: ";
cin >> scale;

cout<<"\nEnter temperature";
cin >> temp;
cout<<"\nCongratulations you entered "
<<scale<<"The following results are your converted temperatures "
<<ftemp(C, F, K)<<endl;

return 0;
}

Any help?
Thanks
 PhysOrg.com science news on PhysOrg.com >> Galaxies fed by funnels of fuel>> The better to see you with: Scientists build record-setting metamaterial flat lens>> Google eyes emerging markets networks
 // Mod4project2tempconvert.cpp : Defines the entry point for the console application. #include using namespace std; double ftemp (double F, double C, double K, double temp, double scale) { while (scale != 0) { if (scale==C) { F=temp*9/5+32; K=temp+273.15; } if (scale==F) { C=(temp-32)*5/9; K=(temp-32)*5/9+273.15; } if (scale==K) { F=(temp-273.15)*9/5+32; C=temp-273.15; } } } int main() { double F, C, K, temp, scale; cout<<"Enter the scale you want to convert from C, F, or K- 0 to quit: "; cin >> scale; cout<<"\nEnter temperature"; cin >> temp; cout<<"\nCongratulations you entered " <
 Recognitions: Staff Emeritus Where are you inputting the values of F, C and K in main?

Recognitions:
Gold Member
Staff Emeritus

## remedial C++

Presumably because he wants the function to just do the calculation.

He posted this also in "homework help" where I suggested that he pass the F,K,C variables by "reference" rather than by "value".
 exactly what is the function suppose to do.... waht is the return "double"variable? and the compiler error you get should be easily solved...look at your function definition and look at your function call as for your function itself, it will either enter a infinite loop because you haven't altered the scale value or while (scale != 0){...} or you won't use the function itself because scale==0.

 Quote by HallsofIvy ...I suggested that he pass the F,K,C variables by "reference" rather than by "value".

double ftemp (double F, double C, double K, double temp, double scale)
you dont return a double;
your function prototype may be something like:
void ftemp (double* F, double* C, double* K, double temp, double scale)

and pass the variables like:
ftemp(&F, &C, &K, temp, scale)

but you will still need to output to screen the values.
 Recognitions: Staff Emeritus Even if you pass the variables by reference how do you expect to do this type of comparison without having an intial value: if (scale==C)

 Quote by dduardo Even if you pass the variables by reference how do you expect to do this type of comparison without having an intial value: if (scale==C)
i would have rewritten the code and give the correct answer but this is "homework help" and therefore i don't want to give the full answer.
 I had it figured out with a more consise program but I accidently earsed it. So I had to redo it it works and should be more than enough to get me a 100% even though it is not as pretty as I would like. // mod4project2.cpp : Defines the entry point for the console application. #include using namespace std; double kscale (double); double fscale (double); double cscale (double); double kscale1 (double); double fscale1 (double); double cscale1 (double); int main() { double k, f, c, temp; char scale; cout<<"Enter temperature: "; cin>>temp; cout<<"\nEnter scale C, F, or K: "; cin>>scale; if (scale=='k' || scale=='K') { k= temp; f=kscale (temp); c= kscale1 (temp); cout<<"\n K= "<
 this code looks ugly yet it may do as you wish. does the code need to have Code: cout<<"\n K= "<>scale; what happens if a user doesnt enter C,F or K? plus your main doesnt return a int which is required by ansii