-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKMSerrorIFELSE.c
48 lines (39 loc) · 1.16 KB
/
KMSerrorIFELSE.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
/* Luciano Scarpaci January 5th 2021
*
* This program converts kilometers to miles or miles to kilometers
*/
#include<stdio.h>
int main()
{
//declare the variables to store the data
double miles, kilometers;
int userChoice;
//print the results to the screen
printf("\n%.2f miles is %.2f kilometers\n", miles, kilometers);
printf("Welcome to the kilometer/ mile calculator. ")
printf("\n---Enter 1 to convert kilometers to miles or ");
printf("\n---Enter 2 to convert miles to kilometers : ");
scanf("%d", userChoice);
if (userChoice == 1)
{
//ask and get distance in kilometers
printf("\nEnter distance in kilometers> ");
scanf("%lf", &kilometers);
//convert kilometers to miles
kilometers = 1.609 * miles;
}
else if (userChoice == 2)
{
//ask and get distance in miles
printf("\nEnter distance in miles> ");
scanf("%lf", &miles);
//convert mil
}
else
{
printf("\nYou did not enter a 1 or a 2\n");
}
//print the results to the screen
printf("\n%.2f miles is %.2f kilometers\n", miles, kilometers);
return 0;
}