@@ -8,40 +8,43 @@ void mass();
8
8
9
9
int main (){
10
10
11
- label1 :
11
+ char retry , category ;
12
12
13
- //clears the terminal screen
14
- system ("cls" );
15
-
16
- char category ;
17
- printf ("Welcome to Unit Converter!\n" );
18
- printf ("Here is a list of converters to choose from: \n" );
19
- printf ("Enter 'T' for Temperature convertion.\n" );
20
- printf ("Enter 'M' for Mass convertion.\n" );
21
- printf ("Entre 'C' for Currency convertion.\n\n" );
22
- printf ("Enter input: " );
23
- scanf (" %c" , & category );
24
-
25
- if (category == 'T' || category == 't' )
26
- temperature ();
27
- else if (category == 'M' || category == 'm' )
28
- mass ();
29
- else if (category == 'C' || category == 'c' )
30
- currency ();
31
- else
32
- printf ("ERROR: Invaild Input. \n " );
33
-
34
- //Prompt for try again ...
35
- char retry ;
36
- printf ("\nDo you wanna try again [y/N]: " );
37
- scanf (" %c" ,& retry );
38
-
39
- if (retry == 'y' || retry == 'Y' )
40
- goto label1 ;
41
- else if (retry == 'n' || retry == 'N' )
42
- printf ("\nProgram Ended, Thanks for testing it." );
43
- else
44
- printf ("\nInvaild Input, Program Ended. " );
13
+ do
14
+ {
15
+ // clears the terminal screen
16
+ system ("cls" );
17
+
18
+ printf ("Welcome to Unit Converter!\n" );
19
+ printf ("Here is a list of converters to choose from: \n" );
20
+ printf ("Enter 'T' for Temperature convertion.\n" );
21
+ printf ("Enter 'M' for Mass convertion.\n" );
22
+ printf ("Entre 'C' for Currency convertion.\n\n" );
23
+ printf ("Enter input: " );
24
+ scanf (" %c" , & category );
25
+
26
+ fflush (stdin );
27
+
28
+ switch (category )
29
+ {
30
+ case 'T' :
31
+ case 't' :
32
+ temperature ();
33
+ case 'M' :
34
+ case 'm' :
35
+ mass ();
36
+ case 'C' :
37
+ case 'c' :
38
+ currency ();
39
+ default :
40
+ printf ("\nError: Invalid Input. \n" );
41
+ }
42
+
43
+ printf ("\nDo you wanna try again [y/N]: " );
44
+ scanf (" %c" , & retry );
45
+ fflush (stdin );
46
+
47
+ } while (retry == 'y' || retry == 'Y' );
45
48
46
49
return 0 ;
47
50
}
@@ -52,6 +55,8 @@ void temperature()
52
55
system ("cls" );
53
56
54
57
int input ;
58
+ float celsius , fahrenheit ;
59
+
55
60
printf ("Welcome to Temperature Converter!\n" );
56
61
printf ("Here is a list of conversion to choose from: \n" );
57
62
printf ("Enter 1 for Celsius to Fahrenheit. \n" );
@@ -64,8 +69,6 @@ void temperature()
64
69
65
70
if (input == 1 )
66
71
{
67
- float celsius , fahrenheit ;
68
-
69
72
printf ("Enter Celisus: " );
70
73
scanf ("%f" ,& celsius );
71
74
@@ -75,8 +78,6 @@ void temperature()
75
78
}
76
79
else if (input == 2 )
77
80
{
78
- float fahrenheit , celsius ;
79
-
80
81
printf ("Enter Fahrenheit: " );
81
82
scanf ("%f" ,& fahrenheit );
82
83
@@ -185,4 +186,4 @@ void currency()
185
186
}
186
187
else
187
188
printf ("ERROR: Invaild Input." );
188
- }
189
+ }
0 commit comments