-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunit_converter.c
More file actions
149 lines (122 loc) · 6.82 KB
/
Copy pathunit_converter.c
File metadata and controls
149 lines (122 loc) · 6.82 KB
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
/* Εισαγωγή βιβλιοθηκών */
#include <stdio.h>
#include <stdlib.h>
int main() {
//Δήλωση Μεταβλητών
char unit; //Μεταβλητή που εκφράζει την εισαγωγή από τον χρήστη της επιλογής του μέσω του χαρακτήρα 'T', 'C', 'M'
char choice; //Μεταβλητή που εκφράζει την εισαγωγή από τον χρήστη της επιλογής του μέσω του χαρακτήρα '1', '2', '3'
float cl, fh, eur, usd, gbp, cny, kg, lb, gr, oz;
printf("Hello, welcome to the application for converting basic units!\n");
printf("The available variables are:\n");
printf("Temperature(T)\nCurrency(C)\nMass(M)\n");
printf("Please type either 'T', or 'C', or 'M'\n"); //Διευκρίνιση
scanf("%c", &unit);
if (unit != 'T' && unit != 'C' && unit != 'M') { //Έλεγχος εγκυρότητας
printf("Error, it seems like something went wrong! Exiting...!\n");
exit(1);
}
if (unit == 'T') { //Εκτελείται αν πληκτρολογηθεί ο χαρακτήρας T
printf("The available conversions are:\n");
printf("Celcius to Fahrenheit (1)\nFahrenheit to Celcius (2)\n");
scanf("%c", &choice);
if (scanf("%c", &choice) != 1) { //Έλεγχος εγκυρότητας στην εισαγωγή χαρακτήρα, από τον χρήστη
printf("Error, it seems like something went wrong! Exiting...\n");
exit(1);
}
if (choice == '1') {
printf("Please enter Temperature in Celcius:\n");
if ((scanf("%f", &cl) != 1)) { //Έλεγχος εγκυρότητας
printf("Error, it seems like something went wrong! Exiting...\n");
exit(1);
}
fh = (cl*1.8) + 32;
printf("%.1f degrees Celsius is equivalent to %.2f degrees Fahrenheit\n", cl, fh);
printf("Thank you for using our conversion application!\n");
} else if (choice == '2') {
printf("Please enter Temperature in Fahrenheit:\n");
if ((scanf("%f", &fh) != 1)) { //Έλεγχος εγκυρότητας
printf("Error, it seems like something went wrong! Exiting...\n");
exit(1);
}
cl = (fh-32) / 1.8;
printf("%.2f degrees Fahrenheit is equivalent to %.1f degrees Celsius\n", fh, cl);
printf("Thank you for using our conversion application!\n");
} else { //Έλεγχος εγκυρότητας
printf("Error, it seems like something went wrong! Exiting...\n");
exit(1);
}
}
if (unit == 'C') { //Εκτελείται αν πληκτρολογηθεί ο χαρακτήρας C
printf("The available conversions are:\n");
printf("EUR to USD (1)\nEUR to GBP (2)\nEUR to CNY (3)\n");
scanf("%c", &choice);
if (scanf("%c", &choice) != 1) { //Έλεγχος εγκυρότητας στην εισαγωγή χαρακτήρα, από τον χρήστη
printf("Error, it seems like something went wrong! Exiting...\n");
exit(1);
}
if (choice == '1') {
printf("Please enter the number of Euros you wish to convert:\n");
if (scanf("%f", &eur) != 1) { //Έλεγχος εγκυρότητας
printf("Error, it seems like something went wrong! Exiting...\n");
exit(1);
}
usd = eur * 1.049; //Dec 05, 2022 18:00 UTC
printf("%.2f Euros is equivalent to %.2f Dollars\n", eur, usd);
printf("Thank you for using our conversion application!\n");
} else if (choice == '2') {
printf("Please enter the number of Euros you wish to convert:\n");
if (scanf("%f", &eur) != 1) { //Έλεγχος εγκυρότητας
printf("Error, it seems like something went wrong! Exiting...\n");
exit(1);
}
gbp = eur * 0.8615; //Dec 05, 2022 18:02 UTC
printf("%.2f Euros is equivalent to %.2f Pound sterling\n", eur, gbp);
printf("Thank you for using our conversion application!\n");
} else if (choice == '3') {
printf("Please enter the number of Euros you wish to convert:\n");
if (scanf("%f", &eur) != 1) { //Έλεγχος εγκυρότητας
printf("Error, it seems like something went wrong! Exiting...\n");
exit(1);
}
cny = eur * 7.307; //Dec 05, 2022 18:02 UTC
printf("%.2f Euros is equivalent to %.2f Chinese Yuan\n", eur, cny);
printf("Thank you for using our conversion application!\n");
} else { //Έλεγχος εγκυρότητας
printf("Error, it seems like something went wrong! Exiting...\n");
exit(1);
}
}
if (unit == 'M') { //Εκτελείται αν πληκτρολογηθεί ο χαρακτήρας M
printf("The available conversions are:\n");
printf("Kg to lb (pounds) (1)\nGr to oz (ounces) (2)\n");
scanf("%c", &choice);
if (scanf("%c", &choice) != 1) { //Έλεγχος εγκυρότητας στην εισαγωγή χαρακτήρα, από τον χρήστη
printf("Error, it seems like something went wrong! Exiting...\n");
exit(1);
}
if (choice == '1') {
printf("Please enter the number of kilograms you wish to convert:\n");
if (scanf("%f", &kg) != 1) { //Έλεγχος εγκυρότητας
printf("Error, it seems like something went wrong! Exiting...\n");
exit(1);
}
lb = kg * 2.205;
printf("%.3f kilograms is equivalent to %.3f pounds\n", kg, lb);
printf("Thank you for using our conversion application!\n");
} else if (choice == '2') {
printf("Please enter the number of grams you wish to convert:\n");
if (scanf("%f", &gr) != 1) { //Έλεγχος εγκυρότητας
printf("Error, it seems like something went wrong! Exiting...\n");
exit(1);
}
oz = gr / 28.35;
printf("%.1f grams is equivalent to %.3f ounces\n", gr, oz);
printf("Thank you for using our conversion application!\n");
} else { //Έλεγχος εγκυρότητας
printf("Error, it seems like something went wrong! Exiting...\n");
exit(1);
}
}
return 0;
}
//Τέλος προγράμματος