forked from sumanchaurasiya/C-Solution
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUnitConverter.c
101 lines (97 loc) · 3.84 KB
/
UnitConverter.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
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
#include <stdio.h>
int main() {
char category;
int tempChoice;
int currencyChoice;
int massChoice;
int userinputF; // User inputted Fahreinheit;
int userinputC; // User inputted Celsius;
int userinputUSDtoEuro; // User inputted for USD to EURO;
int userinputUSDtoJPY; // User inputted for USD to JPY;
int userinputUSDtoRMB; // User inputted for USD to RMB;
int userinputOunce; // User inputted for Ounce;
int userinputGram; // User inputted for Gram;
int fahrenheitToCelcius; // variable that stores the converted F->C;
int celciusToFahrenheit; // variable that stores the converted C->F;
float USDtoEURO ; // varaible that stores the converted USD->EURO;
float USDtoJPY; // stores the converted USD->JPY;
float USDtoRMB; // stores the converted USD->RMB;
float ounceToPounds; // stores the converted Ounce->Pounds;
float gramsToPounds; // stores the vonerted Grams->Pounds;
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.\n");
scanf("%c",&category);
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");
printf("Enter 3 for USD to RMB. \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 if(currencyChoice == 3) {
printf("Please enter the USD amount: \n");
scanf("%d",&userinputUSDtoRMB);
USDtoRMB = userinputUSDtoRMB * 6.82;
printf("RMB: %.2f",USDtoRMB);
}
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;
}