-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathUnitConverter.c
189 lines (152 loc) · 4.16 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#include<stdio.h>
#include<stdlib.h>
//Function ProtoTypes
void temperature();
void currency();
void mass();
int main(){
char retry, category;
do
{
// clears the terminal screen
system("cls");
printf("Welcome to Unit Converter!\n");
printf("Here is a list of converters to choose from: \n");
printf("Enter 'T' for Temperature convertion.\n");
printf("Enter 'M' for Mass convertion.\n");
printf("Entre 'C' for Currency convertion.\n\n");
printf("Enter input: ");
scanf(" %c", &category);
fflush(stdin);
switch (category)
{
case 'T':
case 't':
temperature();
case 'M':
case 'm':
mass();
case 'C':
case 'c':
currency();
default:
printf("\nError: Invalid Input. \n");
}
printf("\nDo you wanna try again [y/N]: ");
scanf(" %c", &retry);
fflush(stdin);
} while (retry == 'y' || retry == 'Y');
return 0;
}
void temperature()
{
//clears the terminal screen
system("cls");
int input;
float celsius, fahrenheit;
printf("Welcome to Temperature Converter!\n");
printf("Here is a list of conversion to choose from: \n");
printf("Enter 1 for Celsius to Fahrenheit. \n");
printf("Enter 2 for Fahrenheit to Celisus. \n");
printf("Enter input: ");
scanf("%d", &input);
//clears the terminal screen
system("cls");
if(input==1)
{
printf("Enter Celisus: ");
scanf("%f",&celsius);
fahrenheit = (celsius * 1.8000) + 32.00;
printf("Fahrenheit: %.2f \n", fahrenheit);
}
else if (input==2)
{
printf("Enter Fahrenheit: ");
scanf("%f",&fahrenheit);
celsius = (fahrenheit - 32)*5/9;
printf("Celsius: %.5f \n",celsius);
}
else
printf("ERROR: Invaild Input.");
}
void mass()
{
//clears the terminal screen
system("cls");
int input;
printf("Welcome to Mass Converter!\n");
printf("Here is a list of conversion to choose from: \n");
printf("Enter 1 for ounces to pounds. \n");
printf("Enter 2 for gram to pounds. \n");
printf("Enter input: ");
scanf("%d",&input);
//clears the terminal screen
system("cls");
if(input==1)
{
int userinputOunce;
float ounceToPounds;
printf("Please enter the ounce amount: ");
scanf("%d",&userinputOunce);
ounceToPounds = userinputOunce * 0.0625;
printf("Pounds: %.2f \n",ounceToPounds);
}
else if (input==2)
{
int userinputGram;
float gramsToPounds;
printf("Please enter the gram amount: ");
scanf("%d",&userinputGram);
gramsToPounds = userinputGram * 0.00220462;
printf("Pounds: %.2f \n",gramsToPounds);
}
else
printf("ERROR: Invaild Input.");
}
void currency()
{
//clears the terminal screen
system("cls");
int input;
float usd, inr, eur, rmb, jpy;
printf("Welcome to Currency Converter! \n");
printf("Here is a list of conversion 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");
printf("Enter 4 for USD to INR. \n");
printf("Enter input: ");
scanf("%d",&input);
//clears the terminal screen
system("cls");
if (input==1)
{
printf("Enter the USD amount: ");
scanf("%f",&usd);
eur = usd * 1.04;
printf("Euro: %.2f \n ",eur);
}
else if (input==2)
{
printf("Enter the USD amount: ");
scanf("%f",&usd);
jpy = usd * 144.84;
printf("Japanese Yen: %.2f \n ",jpy);
}
else if (input==3)
{
printf("Enter the USD amount: ");
scanf("%f",&usd);
rmb = usd * 7.18;
printf("Chinese Yuan: %.2f \n ",rmb);
}
else if (input==4)
{
printf("Enter the USD amount: ");
scanf("%f",&usd);
inr = usd * 81.63;
printf("Indian Rupee: %.2f \n ",inr);
}
else
printf("ERROR: Invaild Input.");
}