#include <iostream>
#include <iomanip>
usingnamespace std;
void celcius(int);
void celciusloop();
int fatemp;
int main()
{
int menu;
cout<<"If you would like to convert a Farenheit temperature to celcius, press 1;" <<endl;
cout<<"Otherwise, press 2 to see a demonstration of the converion program." <<endl;
cin>> menu;
while (menu >2|| menu<1)
{
cout<<"That entry is invalid, please re enter your selection: ";
cin>>menu;
}
while (menu==1)
{
cout<<"This program will convert Farenheit to Celcius for you." <<endl;
cout<<"Please enter the temperature in Farenheit:" <<endl;
cin>>fatemp;
cout<<"Thankyou";
system ("pause");
celcius(fatemp);
cout<<"If you would like to enter another number to convert press 1, otherwise press 2 " <<endl;
cout<<"for the demonstration, or any other number to exit." <<endl;
cin>>menu;
}
if (menu==2)
{celciusloop();
system ("pause");
return 0;
}
else
{
system ("Pause");
return 0;
}
}
void celcius(int fatemp)
{ double celcius;
celcius=5/9*(fatemp-32);
cout<<setprecision(1) <<fixed;
cout<<"The celcius conversion of your temperature is: " <<celcius <<"." <<endl;
system ("pause");
}
void celciusloop()
{
double celcius;
cout<<"Fahrenheit" <<setw(10) <<"Celcius" <<endl;
for (int count=0; count<21; count++)
{
celcius=5/9*(count-32);
cout<<setprecision(1) <<fixed;
cout<<count << "\t\t"<<left <<setw(5) <<celcius <<endl;
}
}
You seem to be doing integer math in your calculations, 5/9 in integer math yields 0. There are no fractions with integers. You need to have at least one of your terms as a floating point type to force floating point math.
void celcius(int fatemp)
{ double celcius;
celcius=5/9*(fatemp-32);
cout<<setprecision(1) <<fixed;
cout<<"The celcius conversion of your temperature is: " <<celcius <<"." <<endl;
system ("pause");
}
We haven't learned what "ftoc" is in class, so my teacher wouldn't like if I used it. What is its purpose? Also, my funtions only have to display, they don't have to return anything to the main function.
You won't find "FtoC" in a textbook, it's just the name of a user-defined function, it can be anything you like. I expect Stewbond chose it as a concise and meaningful way of saying "Fahrenheit to Celsius".
so my teacher wouldn't like if I used it.
It's a function. I'm sure your teacher will be very pleased if you use functions.