-
Notifications
You must be signed in to change notification settings - Fork 12
/
Unit_Converter.c
121 lines (108 loc) · 3.19 KB
/
Unit_Converter.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
#include <stdio.h>
// Function prototypes
void temperatureConverter();
void currencyConverter();
void massConverter();
int main() {
char category;
printf("Welcome to the Enhanced Unit Converter!\n");
printf("Select a conversion category:\n");
printf("T - Temperature\nC - Currency\nM - Mass\n");
printf("Please enter your choice: ");
scanf(" %c", &category);
switch(category) {
case 'T':
case 't':
temperatureConverter();
break;
case 'C':
case 'c':
currencyConverter();
break;
case 'M':
case 'm':
massConverter();
break;
default:
printf("Invalid category. Please restart and enter a valid choice.\n");
}
return 0;
}
void temperatureConverter() {
int choice;
float fahrenheit, celsius, kelvin;
printf("Temperature Conversion Options:\n");
printf("1 - Fahrenheit to Celsius\n");
printf("2 - Celsius to Fahrenheit\n");
printf("3 - Celsius to Kelvin\n");
printf("Enter your choice: ");
scanf("%d", &choice);
if (choice == 1) {
printf("Enter Fahrenheit temperature: ");
scanf("%f", &fahrenheit);
celsius = (fahrenheit - 32) * 5.0 / 9.0;
printf("Celsius: %.2f\n", celsius);
} else if (choice == 2) {
printf("Enter Celsius temperature: ");
scanf("%f", &celsius);
fahrenheit = (celsius * 9.0 / 5.0) + 32;
printf("Fahrenheit: %.2f\n", fahrenheit);
} else if (choice == 3) {
printf("Enter Celsius temperature: ");
scanf("%f", &celsius);
kelvin = celsius + 273.15;
printf("Kelvin: %.2f\n", kelvin);
} else {
printf("Invalid choice. Please restart.\n");
}
}
void currencyConverter() {
int choice;
float usd, converted;
printf("Currency Conversion Options:\n");
printf("1 - USD to Euro\n");
printf("2 - USD to JPY\n");
printf("3 - USD to RMB\n");
printf("Enter your choice: ");
scanf("%d", &choice);
printf("Enter USD amount: ");
scanf("%f", &usd);
switch (choice) {
case 1:
converted = usd * 0.87;
printf("Euro: %.2f\n", converted);
break;
case 2:
converted = usd * 111.09;
printf("JPY: %.2f\n", converted);
break;
case 3:
converted = usd * 6.82;
printf("RMB: %.2f\n", converted);
break;
default:
printf("Invalid choice. Please restart.\n");
}
}
void massConverter() {
int choice;
float inputMass, pounds;
printf("Mass Conversion Options:\n");
printf("1 - Ounces to Pounds\n");
printf("2 - Grams to Pounds\n");
printf("Enter your choice: ");
scanf("%d", &choice);
if (choice == 1) {
printf("Enter mass in ounces: ");
scanf("%f", &inputMass);
pounds = inputMass * 0.0625;
printf("Pounds: %.2f\n", pounds);
} else if (choice == 2) {
printf("Enter mass in grams: ");
scanf("%f", &inputMass);
pounds = inputMass * 0.00220462;
printf("Pounds: %.2f\n", pounds);
} else {
printf("Invalid choice. Please restart.\n");
}
}