FRUSTRATED!

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.




#include
<iostream>

#include
<iomanip>

using
namespace std;


void displayMenu (void);
char getMenuSelection (char choice);
void getStartEndAndIncrement(float& start, float& end, float& increment);
float CtoF(float celsius);
void displayCtoFTable(float start, float end, float increment);
float FtoC(float farh);
void displayFtoCTable(float start, float end, float increment);





int
main()
{




float
start=0,end=0,increment=0;

float
celsius=0,farh=0;

char
userchoice=' ';

do


{

displayMenu ();

userchoice=getMenuSelection (userchoice);

getStartEndAndIncrement (start,end,increment);

if (userchoice=='C' || userchoice=='c')


{

displayCtoFTable(start,end,increment);

}




else
if (userchoice =='F' || userchoice=='f')
{

displayFtoCTable(start,end,increment);

}

}

while (userchoice !='Q'|| userchoice !='q');



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) <<
"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);

displayMenu ();

getMenuSelection ();

break;
}


while
(userchoice != 'C' && userchoice != 'F' &&
userchoice !=
'Q');
}




void
getStartEndAndIncrement(float& start, float& end, float& increment);


{

cout <<
"Enter your starting temperature: ";
cin >> start;

cout <<
'\n';
cout <<
"Enter your ending temperature: ";
cin >> end;

cout <<
'\n';
cout <<
"Enter the temperature increment: ";
cin >> increment;

cout <<
'\n';
}




float
CtoF (float& celsius);


{

float Fa;
Fa = 1.8 * celsius + 32.0;

cout << fixed << cout.precision(1);

return Fa;
}




float
FtoC (float& farh);


{

float Ce;
Ce = (5.0*(farh - 32.0))/9.0;

cout << fixed << cout.precision(1);

return Ce;
}




void
displayCtoFTable (float start, float end, float increment);
{

cout << endl;

cout << setw(10) <<
"Increment: " << increment<<endl;
cout <<
"---------------------------------------------- " << endl;
cout <<
"|*********** Celcius to Farenheit ***********|" << endl;
cout <<
"---------------------------------------------- " << endl;
cout <<
"| C"<<char (248)<<" || F"<<char (248)<<" |" << endl;
cout <<
"---------------------------------------------- " << endl;



for
(float celsius = start; celsius <= end; celsius+=increment)
{

cout <<
"|"<< setw(10)<<celsius<<char(248)<<setw(11)<<"||"

<<setw(13)<<CtoF(celsius)<<
char(248)<<setw(11)<<"|"<<"\n";


}



cout <<
"----------------------------------------------" << endl;
cout <<
"----------------------------------------------" << endl;
cout <<
"\nPress enter to continue...";
cin.ignore(2);



}




void
displayFtoCTable(float start, float end, float increment);
{

cout << endl;

cout << setw(10) <<
"Increment: " << increment<<endl;
cout <<
"----------------------------------------------" << endl;
cout <<
"|*********** Farenheit to Celsius ***********|" << endl;
cout <<
"----------------------------------------------" << endl;
cout <<
"| F"<<char(248)<<" || C"<<char (248)<<" |" << endl;
cout <<
"----------------------------------------------" << endl;



for
(float farh = start; farh <= end; farh+=increment){
cout <<
"|"<< setw(10)<<farh<<char(248)<<setw(11)<<"||"

<<setw(13)<<FtoC(farh)<<
char(248)<<setw(9)<<"|"<<"\n";}


cout <<
"----------------------------------------------" << endl;
cout <<
"----------------------------------------------" << endl;
cout <<
"\nPress enter to continue...";
cin.ignore(2);

}



?


return
(0);


?

?

}



1>------ Build started: Project: Week 5, Configuration: Debug Win32 ------

1> Fah_Cel.cpp

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

1>C:\Users\Brad\Documents\Visual Studio 2010\Projects\Week 5\Debug\Week 5.exe : fatal error LNK1120: 8 unresolved externals

========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Last edited on
please use code tags with proper indentation so we dont get a headache trying to read it, thanks!

EDIT: you also might want to organize the program a little better before posting it, delete extra spaces and make sure it's easy to read.
Last edited on
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:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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";
}
Last edited on
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

What does that mean?



int main()
{

float start=0,end=0,increment=0;
float celsius=0,farh=0;
char userchoice= ' ';

do
{
displayMenu ();
getMenuSelection (userchoice);
getStartEndAndIncrement (start,end,increment);
if (userchoice=='C' || userchoice=='c')

{
displayCtoFTable(start,end,increment);
}

else if (userchoice =='F' || userchoice=='f')

{
displayFtoCTable(start,end,increment);
}
}
while (userchoice !='Q'|| userchoice !='q');

return (0);
}



Look for the difference between the declaration and the definition of that function.
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;


void displayMenu (void);
char getMenuSelection (char userchoice);
void getStartEndAndIncrement(float& start, float& end, float& increment);
float CtoF(float celsius);
void displayCtoFTable(float start, float end, float increment);
float FtoC(float farh);
void displayFtoCTable(float start, float end, float increment);


int main()
{

float start=0,end=0,increment=0;
float celsius=0,farh=0;
char userchoice= ' ';

do
{
displayMenu ();
cout << "Userchoice: " << userchoice << " Start: " << start << " End: " << end << " Increment: " << increment << endl;
getMenuSelection (userchoice);
cout << "Userchoice: " << userchoice << " Start: " << start << " End: " << end << " Increment: " << increment << endl;
getStartEndAndIncrement (start,end,increment);
cout << "Userchoice: " << userchoice << " Start: " << start << " End: " << end << " Increment: " << increment << endl;
if (userchoice=='C' || userchoice=='c')

{
displayCtoFTable(start,end,increment);
}

else if (userchoice =='F' || userchoice=='f')

{
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);
}
For the love of Dennis Ritchie, please please please, use code tags!
Here:
char getMenuSelection (char userchoice);
Change to:
char getMenuSelection (char &userchoice);

Here:
1
2
char getMenuSelection (char userchoice)
{

Change to:
1
2
char getMenuSelection (char &userchoice)
{
Topic archived. No new replies allowed.