Having a little frustration doing this program for my class. It is supposed to a program designed to convert Fahrenheit to Celcius and Celcius to Fahrenhiet
from a beginning point to an ending point by a certain increment using functions.
I have attached my code. One of the errors it is telling me I am using unitialized local variables celsius. I have tried putting it in the main, I have tried putting it in the functions (CtoF and displayCtoFTable) I have been working on this for 3 days and I think I am just getting more and more confused. I feel like I have everything set up the way it needs to be. I think I just need another pair of eyes to look at it. I have also at the very bottom put the compiler error list I get with this.
cout << right << setw(45) <<
"Celsius and Fahrenheit Temperation Converter" << endl;
cout <<
"\n";
cout << right << setw(45) <<
"Please choose from the following options" << endl;
cout <<
"\n";
cout << right << setw(45) <<
"Celsius to Fahrenhiet <C> " << endl;
cout << right << setw(45) <<
"Fahrenheit to Celsius <F> " << endl;
cout << right << setw(45) <<
"Quit <Q> " << endl;
cout <<
"\n";
}
char
getMenuSelection ();
{
cout <<
"Enter your choice: ";
cin >> userchoice;
switch
(userchoice)
{
case 'c':
case 'C':
cout <<
"You have choses a Celsius to Fahrenheit conversion. "<<endl;
return userchoice;
break;
case 'f':
case 'F':
cout <<
"You have chosen a Fahrenheit to Celsius conversion. "<<endl;
return userchoice;
break;
case 'q':
case 'Q':
cin.get();
cout <<
"You have quit the program. Press enter to exit the program."<<endl;
cin.get();
exit(0);
return userchoice;
break;
}
do
{
cout << endl;
cout <<
"Invalid choice, press enter to continue. "<<endl;
cin.ignore(2);
1>c:\users\brad\documents\visual studio 2010\projects\week 5\week 5\fah_cel.cpp(126): warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
1>c:\users\brad\documents\visual studio 2010\projects\week 5\week 5\fah_cel.cpp(128): warning C4244: 'return' : conversion from 'float' to 'int', possible loss of data
1>c:\users\brad\documents\visual studio 2010\projects\week 5\week 5\fah_cel.cpp(135): warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
1>c:\users\brad\documents\visual studio 2010\projects\week 5\week 5\fah_cel.cpp(137): warning C4244: 'return' : conversion from 'float' to 'int', possible loss of data
1>Fah_Cel.obj : error LNK2019: unresolved external symbol "float __cdecl FtoC(float &)" (?FtoC@@YAMAAM@Z) referenced in function _main
1>Fah_Cel.obj : error LNK2019: unresolved external symbol "float __cdecl CtoF(float &)" (?CtoF@@YAMAAM@Z) referenced in function _main
1>Fah_Cel.obj : error LNK2019: unresolved external symbol "char __cdecl getMenuSelection(void)" (?getMenuSelection@@YADXZ) referenced in function _main
1>Fah_Cel.obj : error LNK2019: unresolved external symbol "void __cdecl displayFtoCTable(float,float,float)" (?displayFtoCTable@@YAXMMM@Z) referenced in function _main
1>Fah_Cel.obj : error LNK2019: unresolved external symbol "void __cdecl displayCtoFTable(float,float,float)" (?displayCtoFTable@@YAXMMM@Z) referenced in function _main
1>Fah_Cel.obj : error LNK2019: unresolved external symbol "void __cdecl getStartEndAndIncrement(float &,float &,float &)" (?getStartEndAndIncrement@@YAXAAM00@Z) referenced in function _main
1>Fah_Cel.obj : error LNK2019: unresolved external symbol "char __cdecl getMenuSelection(char)" (?getMenuSelection@@YADD@Z) referenced in function _main
1>Fah_Cel.obj : error LNK2019: unresolved external symbol "void __cdecl displayMenu(void)" (?displayMenu@@YAXXZ) referenced in function _main
As I said in your other thread, you need to move all function definitions outside of main, You also need to remove semi-colons from function definitions. Example:
void displayMenu ();//this semi-colon, some of the other functions have a semi-colon here aswell.
{ //they need to be removed.
cout << right << setw(45) <<
"Celsius and Fahrenheit Temperation Converter" << endl;
cout <<
"\n";
cout << right << setw(45) <<
"Please choose from the following options" << endl;
cout <<
"\n";
cout << right << setw(45) <<
"Celsius to Fahrenhiet <C> " << endl;
cout << right << setw(45) <<
"Fahrenheit to Celsius <F> " << endl;
cout << right << setw(45) <<
"Quit <Q> " << endl;
cout <<
"\n";
}
So I now have it resolved that the functions are outside of the main, but I am getting this error - 1>Fah_Cel.obj : error LNK2019: unresolved external symbol "char __cdecl getMenuSelection(char)" (?getMenuSelection@@YADD@Z) referenced in function _main
I am very close on this program but I need some more help please. (Just as a sidenote - the # is not on the right side of my edit so I am unable to put it into code. I apologize for that.) Everything works except that my getMenuSelection does not return a value for userchoice. I put in some cout output statements to show what the values are and nothing is coming through for userchoice. Please - any assistance would be appreciated. I have put the code that deals with that below:
#include <iostream>
#include <iomanip>
using namespace std;
{
displayFtoCTable(start,end,increment);
}
}
while (userchoice !='Q'|| userchoice !='q');
return (0);
}
void displayMenu ()
{
cout << right << setw(45) << "Celsius and Fahrenheit Temperation Converter" << endl;
cout << "\n";
cout << right << setw(45) << "Please choose from the following options" << endl;
cout << "\n";
cout << right << setw(45) << "\n Celsius to Fahrenhiet <C> " << endl;
cout << right << setw(45) << "\n Fahrenheit to Celsius <F> " << endl;
cout << right << setw(45) << "\n Quit <Q> " << endl;
cout << "\n";
}
char getMenuSelection (char userchoice)
{
char choice;
cout << "\n Enter your choice: ";
cin >> choice;
switch (choice)
{
case 'c':
case 'C':
cout <<"\n You have chosen a Celsius to Fahrenheit conversion. "<<endl;
return userchoice;
break;
case 'f':
case 'F':
cout <<"\n You have chosen a Fahrenheit to Celsius conversion. "<<endl;
return userchoice;
break;
case 'q':
case 'Q':
cin.get();
cout <<"\n You have quit the program. Press enter to exit the program."<<endl;
cin.get();
exit(0);
return userchoice;
break;
}
do
{
cout << endl;
cout << "\n Invalid choice, press enter to continue. "<<endl;
cin.ignore(2);
displayMenu ();
getMenuSelection (userchoice);
return userchoice;
break;
}
while (userchoice != 'C' && userchoice != 'c' && userchoice != 'F' && userchoice !='f' &&
userchoice != 'Q' && userchoice);
}