Help with functions


its been a while since I've posted here....been busy with other classes and such but I am back and need help with functions. While I understand the concept, I cant quite nail it down syntactically. Please help me with the code I've posted below. I usually like to keep my helplessness to a minimum but there comes a time to stop beating my head against a wall.

I want to have a function that queries for input pass it through a calculation function. Eventually, I will need to write it to and retrieve it from a file.

code begins here..........

#include <iostream>

using namespace std;
//-------------------Function declarations
int GetUserInput();
int ConvertTemp();
//-------------------Main body
int main()
{
float ConvertedTemp;
GetUserInput();
ConvertedTemp = ConvertTemp(CelsiusTemp);
cout << CelsiusTemp << endl;
return 0;
}//end main
//------------------Functions
int GetUserInput ()
{
//------------------Local variables
float CelsiusTemp;
//---------------------------------
cout<< "Enter Celcius Temperature to Convert::" << endl;
cin>>CelsiusTemp;
//cout<< CelsiusTemp << endl;
return (CelsiusTemp);
}//end GetUserInput
int ConvertTemp (float CelsiusTemp)
{
float ConvertedTemp;
ConvertedTemp = (9.0/5.0) * CelsiusTemp + 32.0;
}//end ConvertTemp
Last edited on
Well, when you return CelciusTem, you're not actually returning a variable called CelciusTemp that you can use. You're returning the value. If you don't do anything with that value (such as assign it to a variable) then it's lost. So, set a variable of your choice to be equal to GetUserInput(), and then plug that in where you have CelciusTemp in your ConvertTemp function. Also, your ConvertTemp function should have, in parenthesis (both in declaration and definition) (int CelciusTemp). If you're going to pass an argument to it, you have to specify. Then ConvertTemp would have to return the value of ConvertedTemp, which you then set equal to the variable ConvertedTemp in main. You then should display convertedTemp, not CelciusTemp.
So first off its gonna be:
"Variable" = GetUserInput(); ?

along with the declarations.....

That kinda makes sense.


I can't work on it again until tomorrow night since I don't have a compiler on my work computer.

Thanks for your help.
sorry, I forgot to let you know that i fixed it like you advised and it worked.

Thanks for the help
Topic archived. No new replies allowed.