need help with program in xcode

the following program is supposed to take an input to choose to convert from F to C or C to F. The problem i am having right now is that it is telling me that no function exists for FtoC or CtoF and as you can see below, the function clearly exists. I use Visual Studio in class but have to use xcode at home as I have a Mac and there seems to be a few differences when programming ( I think, i am probably a moron but this is killing me). I need help fixing this and my prof is out to lunch. any help would be greatly appreciated.

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

//void getdisplayMenu( );
//void getMenuSelection (char a);
//void getStartEndAndIncrement(float& st, float& ending, float& i);
//void getCtoF(float Fahr);
//void getFtoC(float Celsius);
void displayMenu( )
{
cout<< "Would you like to convert from 'C'elsius to Fahrenheit; 'F'ahrenheit to Celsius; or 'Q'uit: ";
}
void MenuSelection (char a)
{
char b;
cin >> b;
a=b;
}
void getStartEndAndIncrement(float& st, float& ending, float& i)
{
cout<< "Input the starting temp:";
cin >> st;
cout << "Input the ending temp: ";
cin >> ending;
cout << "Input the increment of calculation: ";
cin >> i;
}
void CtoF(float q)
{
float Fahr;
Fahr= (9.0*q)/5.0+32.0;
}
void FtoC(float q)
{
float Celsius;
Celsius= 5.0*(q-32.0)/9.0;
}
void displayTable( )
{
cout << fixed << setprecision (2);
cout << setw(8) << char (248)<< "C" << setw (8) << char (248) << "F" << endl;
}
int main()
{
char a;
float st, ending, i, Celsius, Fahr;
displayMenu();
getStartEndAndIncrement(st, ending, i);
MenuSelection(a);
for(float q=st;q<ending;q=q+i)
{
switch(a)
{
case 'C':
CtoF(Fahr);
break;
case 'F':
FtoC (Celsius);
break;
case 'Q':
break;
}
cout << setw(4) << Celsius << setw (6) << Fahr << endl;
}
return 0;
}
Do these things and it should work:
1.In your CtoF() function, add 'return Fahr;' at the end of the function.
2.In your FtoC() function, add 'return Celcius;' at the end of the function.
3.In your main() function, add 'float Fahr = ' at the beginning of the line where you wrote 'CtoF(Fahr)'.
4.In your main() function, add 'float Celcius = ' at the beginning of the line where you wrote 'FtoC(Celcius)'.

That should work.
1. it gives an error "cannot return value for void function"
2. same as 1
3. it gives the error "cannot initialize a variable of type 'float' with an rvalue of type void
4. same

Thanks for the help but I have to turn this in. I did finally get it to compile, problem is it is giving all 0's for temps can't figure that one out either.

new program :

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

void displayMenu()
{
cout << "Would you like to convert from 'C'elsius to Fahrenheit; 'F'ahrenheit to Celsius; or 'Q'uit: ";
}
void MenuSelection (char a)
{
cin >> a;
}
void StartEndAndIncrement(float & st, float & ending,float & i)
{
cout<< "Input the starting temp:";
cin >> st;
cout << "Input the ending temp: ";
cin >> ending;
cout << "Input the increment of calculation: ";
cin >> i;
}
void CtoF(float q)
{
float Fahr=0.0;
Fahr = (9.0*q)/5.0+32.0;
}
void FtoC(float& q)
{
float Celsius= 0.0;
Celsius= 5.0*(q-32.0)/9.0;
}
int main()
{
char a = 0;
float st=0.0, ending=0.0, i=0.0, Celsius=0.0, Fahr=0.0;
displayMenu ();
MenuSelection (a);
StartEndAndIncrement (st, ending, i);
cout << setw (5) << char(248) << "C" << setw (8) << char (248) << "F" << endl;
for(float q=st;q<ending;q=q+i)
{
switch(a)
{
case 'C':
CtoF(Fahr);
break;
case 'F':
FtoC(Celsius);
break;
case 'Q':
break;
}

cout << setw(4) << Celsius << setw (6) << Fahr << endl;
}
return 0;
}
Make Celsius and Fahr as Global variable.
and remove declaration of that variable from function CtoF(.....) and FtoC(...)
like this
1
2
3
4
void FtoC(float& q)
{
    Celsius= 5.0*(q-32.0)/9.0;
}

please use code tags..
Do NOT use global variables. Either pass values by reference, create a data type function beside void, or both. Refrain from using any global variables unless absolutely necessary.
Just change the 'void' from the functions to 'int'. It should work.
And for my 3. and 4., just change the name of the variables to something else. (eg. 'float Celcius = FtoC(Celcius);' -> 'float Cel = FtoC(Celcius);
Topic archived. No new replies allowed.