-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
117 lines (44 loc) · 1.78 KB
/
main.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
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main() { //beginning of the function
float conversion; //variable operands
float conversion_reverse;
int choice;
float mp_h;
float km_h = 1.609; //variables for choice
int decision; //variables for decision
printf("km/h2mp/h converter by Fabio - v1.0a \n");
do {
printf("Wich unit do you want to convert? 1(Mp/h) 2(km/h) 3(Exit)\n"); //Unit choice.
scanf("%d", &choice);
switch (choice) { //using switch for multiple cases, linked to the user choise.
case 1: //mp_h 2 km_H
do {
printf("Insert mp/h number \n");
scanf("%f", &mp_h);
conversion = mp_h * km_h; //operand for conversion
printf("Converting to km/h... \n");
printf("%f\n", conversion); //output operand
printf("Do you want to continue? 1(Yes) 2(No) \n");
scanf("%d", &decision);
} while (decision == 1);
break; //pause instruction.
case 2: //km_h 2 mp_h
do {
printf("Insert km/h number \n");
scanf("%f", &km_h);
conversion = km_h / mp_h; //operand for conversion
printf("Converting to km/h... \n");
printf("%f\n", conversion); //output operand
printf("Do you want to continue? 1(Yes) 2(No) \n");
scanf("%d", &decision);
} while (decision == 1);
break;
default: //any value that it's not recognized inside the switch parameter. Used to exit the program.
printf("Exiting program...\n");
system("PAUSE");
break;
}
} while (choice !=3); //has to be different from number 3, or else it will close)
}