-
Notifications
You must be signed in to change notification settings - Fork 7
/
C.c
68 lines (54 loc) · 1.74 KB
/
C.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
// -----------------------------------------------------------------------------
// https://lptcp.blogspot.com/
//
/*
Chapter 22 - Exercise 6
For each language mentioned in this chapter, look at a popular textbook and
see what is used as the first complete program. Write that program in all of
the other languages. Warning: This could easily be a 100-program project.
The exercise I chose is Chapter 3 - Exercise 2:
"Write a program in C++ that converts from miles to kilometres"
C
Built and written using Visual Studio Code on Windows 10 (with the MSVC compiler)
*Note - Please see my github for the build task if you're interested
*/
// https://github.com/l-paz91/principles-practice/
// -----------------------------------------------------------------------------
//--INCLUDES--//
#include <stdio.h>
#include <stdbool.h>
// -----------------------------------------------------------------------------
bool checkQuit()
{
printf("Quit? y / n\n>> ");
char ans;
ans = getchar();
if(ans == 'y')
{
return true;
}
else
{
return false;
}
}
// -----------------------------------------------------------------------------
int main()
{
const double m2k = 1.60934;
printf("This program converts miles to kilometers.");
bool quit = false;
double miles = 0.0;
while (!quit)
{
printf("\nMiles To Convert: ");
scanf("%lf", &miles);
getchar(); // to consume newline created by scanf
printf("\n>> %lf km\n", miles * m2k);
quit = checkQuit();
}
return 0;
}
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------