-
Notifications
You must be signed in to change notification settings - Fork 0
/
code.c lang
101 lines (92 loc) · 3.41 KB
/
code.c lang
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/******************************************************************************
UNIT CONVERTER THROUGH C LANGUAGE ,B JATHIN SANJAY ,RA2111026010450,CSE AIML,T2 SECTION
*******************************************************************************/
#include <stdio.h>
int main() {
char category;
int tempChoice;
int currencyChoice;
int massChoice;
int userinputF;
int userinputC;
int userinputUSDtoEuro;
int userinputUSDtoJPY;
int userinputOunce;
int userinputGram;
int fahrenheitToCelcius;
int celciusToFahrenheit;
float USDtoEURO ;
float USDtoJPY;
float ounceToPounds;
float gramsToPounds;
printf("Welcome to Unit Converter! \n");
printf("Here is a list of conversation to choose from: \n");
printf("Temperature(T),Currency(C),Mass(M) \n");
printf("Please enter the letter you want to convert.Please enter your choice in capital!!\n");
scanf("%c",&category);
system("clear");
if(category == 'T'){
printf("Welcome to Temperature Converter! \n");
printf("Here is a list of conversations to choose from: \n");
printf("Enter 1 for Fahrenheit to Celsius. \n");
printf("Enter 2 for Celsius to Fahrenheit. \n");
scanf("%d",&tempChoice);
if(tempChoice == 1){
printf("Please enter the Fahrenheit degree: \n");
scanf("%d",&userinputF);
fahrenheitToCelcius = ((userinputF-32) * (5.0/9.0));
printf("Celcius: %d",fahrenheitToCelcius);
}
else if(tempChoice == 2){
printf("Please enter the Celcius degree: \n");
scanf("%d",&userinputC);
celciusToFahrenheit = ((9.0/5.0)*userinputC + 32);
printf("Fahrenheit: %d",celciusToFahrenheit);
}
else
printf("Please enter the correct choice. \n");
}
else if(category == 'C') {
printf("Welcome to Currency Converter! \n");
printf("Here is a list of conversations to choose from: \n");
printf("Enter 1 for USD to Euro. \n");
printf("Enter 2 for USD to JPY. \n");
scanf("%d",¤cyChoice);
if(currencyChoice == 1){
printf("Please enter the USD amount: \n");
scanf("%d",&userinputUSDtoEuro);
USDtoEURO = userinputUSDtoEuro * 0.87;
printf("Euro: %.2f",USDtoEURO); // %.2f = rounds the float to only 2 decimal places;
}
else if(currencyChoice == 2){
printf("Please enter the USD amount: \n");
scanf("%d",&userinputUSDtoJPY);
USDtoJPY = userinputUSDtoJPY * 111.09;
printf("JPY: %.2f",USDtoJPY);
}
else
printf("Please enter correct choice. \n");
}
else if(category == 'M'){
printf("Welcome to Mass Converter! \n");
printf("Here is a list of conversations to choose from: \n");
printf("Enter 1 for ounces to pounds. \n");
printf("Enter 2 for gram to pounds. \n");
scanf("%d",&massChoice);
if(massChoice == 1){
printf("Please enter the ounce amount: \n");
scanf("%d",&userinputOunce);
ounceToPounds = userinputOunce * 0.0625;
printf("Pounds: %.2f",ounceToPounds);
}
else if(massChoice == 2) {
printf("Please enter the gram amount: \n");
scanf("%d",&userinputGram);
gramsToPounds = userinputGram * 0.00220462;
printf("Pounds: %.2f",gramsToPounds);
}
else
printf("Please enter the correct choice. \n");
}
return 0;
}