- 2

Can anyone fix all the problems in this code?

#include<studio.h> #include <string.h> int main(); { float fh, cl; int 3choice; printf("\n1: Convert temperature from Fahrenheit to Celsius."); printf("\n2: Convert temperature from Celsius to Fahrenheit."); printf("\nEnter your choice(1, 2”:); scanf("%d",choice); if(choice = =1);{ printf("\nEnter temperature in Fahrenheit: "); scanf("%lf",&fh); cl = (fh - 32) / 1.8; printf("Temperature in Celsius: %.2f",cl); } else if ( choice = 2 ){ printf("\nEnter temperature in Celsius: "); scanf("%f",&cl); fh= (cl*1.8)+32; printf("Temperature in Fahrenheit: %.2f",fh); } Else ( choice = =3) { printf("\nInvalid Choice !!!"); } return 0; }

4th Jul 2021, 8:15 AM
Siyam
Siyam - avatar
2 Answers
+ 2
Are you sure you have written this code. In your code i have seen lots of mistakes somewhere u put bracket unnecessary u dont need to put anywhere your if esle is misleading. You have not included headerfile properly in if condition u written semicolon how next statements will execute your 3choice variable is not valid in scanf choice here u forget ampersand in scanf u have written %lf for float. In else statement your E should be small
4th Jul 2021, 8:28 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 2
#include<stdio.h> #include <string.h> int main() { float fh, cl; int choice; printf("\n1: Convert temperature from Fahrenheit to Celsius."); printf("\n2: Convert temperature from Celsius to Fahrenheit."); printf("\nEnter your choice(1, 2:)"); scanf("%d",&choice); if(choice ==1) { printf("\nEnter temperature in Fahrenheit: "); scanf("%f",&fh); cl = (fh - 32) / 1.8; printf("Temperature in Celsius: %.2f",cl); } else if( choice == 2 ){ printf("\nEnter temperature in Celsius: "); scanf("%f",&cl); fh= (cl*1.8)+32; printf("Temperature in Fahrenheit: %.2f",fh); } else { printf("\nInvalid Choice !!!"); } return 0; }
4th Jul 2021, 8:29 AM
A S Raghuvanshi
A S Raghuvanshi - avatar