-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcash.c
96 lines (76 loc) · 1.57 KB
/
cash.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
#include <stdio.h>
#include <cs50.h>
#include <math.h>
int main(void)
{
// Get the value of the user and validating
float dollars;
do
{
dollars = get_float("Change owed: ");
}
while (dollars <= 0);
// Multiply value in cents for 100
int cents = round(dollars * 100);
// Cents
int twentyfive = 25;
int ten = 10;
int five = 5;
int two = 2;
int one = 1;
// Total times I use the coins
int total = 0;
// If it is greater than or equal to Twenty-five
if (cents >= twentyfive)
{
do
{
cents = cents - twentyfive;
// Added times the coin was used
total++;
}
while (cents >= twentyfive);
}
// If it is greater than or equal to ten
if (cents >= ten)
{
do
{
cents = cents - ten;
total++;
}
while (cents >= ten);
}
// If it is greater than or equal to five
if (cents >= five)
{
do
{
cents = cents - five;
total++;
}
while (cents >= five);
}
// If it is greater than or equal to two
if (cents >= two)
{
do
{
cents = cents - two;
total++;
}
while (cents >= two);
}
// If it is greater than or equal to one
if (cents >= one)
{
do
{
cents = cents - one;
total++;
}
while (cents >= one);
}
// print the total of coins was used
printf("%i\n", total);
}