Hello!
I have a problem with my C program. I want to calculate Fahrenheit in Celsius and reverse, but it doesnīt work yet. Maybe I just got a mistake that I canīt figure out?
Additionally, is is there any possibility for shortening the if else statements? for example that the program doesnīt need printf in each if statement.
Thank you very much!
error messages:Code://starts by including libaries #include<stdio.h> #include<stdlib.h> #include<math.h> //Defines the two Function for calculating Celsius into Fahrenheit and reverse) float CelsiusInFahrenheit(float Celsius) { return Celsius * 1.8 + 32; } float FahrenheitInCelsius(float Fahrenheit) { return (Fahrenheit - 32) / 1.8; } main() { int i; float temperature; printf("Type (1) for calculating Celsius in Fahrenheit or (2) for Fahrenheit in Celsius: \n"); scanf("%d",&i); if(i=1) { printf("Please type in the amount of Fahrenheit \n"); scanf("%f",&temperature); printf("%4.2f Fahrenheit are %4.2f Celsius. \n", temperature, CelsiusInFahrenheit(temperature); }; else if(i=2) { printf("Please type in the amount of Celsius \n"); scanf("%f",&temperature); printf("%4.2f Celsius are %4.2f Fahrenheit. \n", temperature, FahrenheitInCelsius(temperature); } else printf("Wrong input! Program will be closed"); }
D:\Programme\Dev-Cpp\CelsiusFahrenheitConverter in C.c: In function `main':
D:\Programme\Dev-Cpp\CelsiusFahrenheitConverter in C.c:33: error: syntax error before ';' token
D:\Programme\Dev-Cpp\CelsiusFahrenheitConverter in C.c:35: error: syntax error before "else"
D:\Programme\Dev-Cpp\CelsiusFahrenheitConverter in C.c:38: error: syntax error before ';' token