Code: Select all
#include <iostream.h>
float converttocel(float);
float converttofahr(float);
int main()
{
float tempFahr,tempCel;
int input;
cout << "Welcome to the temperature conversion program. Would you like to\n convert from Fahrenheit to Celsius [1] or Celsius to Fahrenheit? [2]\n Your choice number:";
cin >> input;
if (input==1) (input==2); // IF number is 1 OR 2
{
if (input==1) // IF number is 1
{
cout << "You have chosen to convert from Fahrenheit to Celsius. Please\n enter your Fahrenheit value:";
cin >> tempFahr;
cout << "The Celsius equivalent to your Fahrenheit value is" << converttocel(tempFahr) << " degrees.";
}
else // IF number is not 1, i.e. 2
{
cout << "You have chosen to convert from Celsius to Fahrenheit. Please \n enter your Celsius value:";
cin >> tempCel;
cout << "The Fahrenheit equivalent to your Celsius value is " << converttofahr(tempCel) << " degrees.";
}
}
if (input<3) // THis is where i found the problem. there was a else here...
{
cout << "You idiot. Can't even type 1 or 2..... but i'm no better; i can't even loop the program\n so that it will ask again for the input ";
}
return 0;
}
float converttofahr(float tempCel)
{
float tempFahr;
tempFahr=((tempCel*9)/5)+32;
return tempFahr;
}
float converttocel(float tempFahr)
{
float tempCel;
tempCel=((tempFahr-32)*5)/9;
return tempCel;
}
