program that gives the user the option of converting Fahrenheit to Celsius or Celsius to Fahrenheit. Then carry out the conversion. Use floating-point numbers. Interaction with the program might look like this: Type 1 to convert Fahrenheit to Celsius, 2 to convert Celsius to Fahrenheit: 1 Enter temperature in Fahrenheit: 70 In Celsius that’s 21.111111
Answers
Answer:
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
#include<stdlib.h>
void main()
{
int x;
double c,f;
while(1)
{
cout<<"\n1. For Celsius To Fahrenheit. \n";
cout<<"2. For Fahrenheit To Celsius. \n";
cout<<"3. For Exit\n\n";
cout<<"Enter Your Choice \n ";
cin>>x;
switch(x)
{
case 1:
cout<<"\nEnter The Temperature In Celsius\n";
cin>>c;
f=(c*9/5)+32;
cout<<"\nTemperature In Fahrenheit Is = "<<f
;
break;
case 2:
cout<<"\nEnter The Temperature In Fahrenheit\n";
cin>>f;
c=(f-32)*5/9;
cout<<"\nTemperature In Celsius Is = "<<c ;
break;
case 3:
cout<<"Process Completed...";
exit(1);
default:
cout<<"\nEnter The Right Choice \n";
break;
} }
}
Explanation:
HOPE THIS WOULD HELP YOU !
This program is in Java and I have Double because it has a wider range. I have also added all the possible outputs ^_^
import java.util.Scanner;
public class CelciusToFahrenheit{
public static void main (String [] args){
Scanner sc = new Scanner(System.in);
System.out.println("Press 0 for Celcius to Fahrenheit and 1 for Vice-Versa");
double choice = sc.nextDouble();
if (choice == 0){
System.out.print("Enter the temperature in Celcius: ");
double tempC = sc.nextDouble();
double tempF = (tempC*1.8) + 32;
System.out.println("The temperature in Fahrenheit: " + tempF + "°F");}
if (choice == 1){
System.out.print("Enter the temperature in Fahrenheit: ");
double tempF = sc.nextDouble();
double tempC = (tempF - 32)/1.8;
System.out.println("The temperature in Celcius: " + tempC + "°C");}
if (choice != 0 && choice != 1)
System.out.println("Enter only 1 or 2 :(");
}
}
Output:
(i)
Press 1 for Celcius to Fahrenheit and 2 for Vice-Versa
123
Enter only 1 or 2 :(
(ii)
Press 1 for Celcius to Fahrenheit and 2 for Vice-Versa
1
Enter the temperature in Celcius: 37
The temperature in Fahrenheit: 98.60000000000001°F
(iii)
Press 1 for Celcius to Fahrenheit and 2 for Vice-Versa
2
Enter the temperature in Fahrenheit: 98.6
The temperature in Celcius: 36.99999999999999°C