forked from akn714/1st-yr-c-programs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
4.c
34 lines (29 loc) · 1010 Bytes
/
4.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Task : WAP that accepts the temperature in Centigrade and converts in Fahrenheit and vise versa using the formula c / 5 = (f-32) / 9
#include <stdio.h>
int main() {
float c, f;
int opt;
printf("1 : centigrade to fahrenheit\n2 : fahrenheit to centigrade\nchoose an option [1/2] : ");
// invalidOpt is a label
invalidOpt:
scanf("%d", &opt);
switch(opt){
case 1:
printf("enter centigrade temprature : ");
scanf("%f", &c);
f = (c*9)/5 + 32;
printf("temprature in fahrenheit : %.2f\n", f);
break;
case 2:
printf("enter fahrenheit temprature : ");
scanf("%f", &f);
c = (f - 32)*5.0/9;
printf("temprature in centigrade : %.2f\n", c);
break;
default:
// taking the input again if the option (opt) is invalid
printf("please choose a valid option : ");
goto invalidOpt;
}
return 0;
}