#include
#include
using namespace std;
// declare functions
void display_menu();
void convert_temp();
double to_celsius(double fahrenheit);
double to_fahrenheit(double celsius);
int main() {
cout < "convert="">
display_menu();
char again = 'y';
while (again == 'y')
{
convert_temp();
cout < "convert="" another="" temperature?="" (y/n):="">
cin >> again;
cout <>
}
cout <>
}
// define functions
void display_menu()
{
cout <>
< "1.="" fahrenheit="" to="">
< "2.="" celsius="" to="">
}
void convert_temp()
{
int option;
cout < "enter="" a="" menu="" option:="">
cin >> option;
double f = 0.0;
double c = 0.0;
switch (option)
{
case 1:
cout < "enter="" degrees="" fahrenheit:="">
cin >> f;
c = to_celsius(f);
c = round(c * 10) / 10; // round to one decimal place
cout < "degrees="" celsius:="" "="">< c=""><>
break;
case 2:
cout < "enter="" degrees="" celsius:="">
cin >> c;
f = to_fahrenheit(c);
f = round(f * 10) / 10; // round to one decimal place
cout < "degrees="" fahrenheit:="" "="">< f=""><>
break;
default:
cout < "you="" must="" enter="" a="" valid="" menu="">
break;
}
}
double to_celsius(double fahrenheit)
{
double celsius = (fahrenheit - 32.0) * 5.0 / 9.0;
return celsius;
}
double to_fahrenheit(double celsius)
{
double fahrenheit = celsius * 9.0 / 5.0 + 32.0;
return fahrenheit;
}
Now, modify it to do the following:
- Add the factorial function that works by using recursion.