-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcs 50 greedy cash
75 lines (52 loc) · 1.25 KB
/
cs 50 greedy cash
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
#include <stdio.h>
#include <cs50.h>
#include <math.h>
int main(void)
{
float cash;
int cents;
int counter =0;
do{
printf("O hai! How much change is owed?\n");
cash = get_float();
}
while (cash<0);
// take input the amount of cash owned
cents = cash * 100;
cents = round(cash*100);
if (cents % 25 == 0)
{
counter += round(cents / 25);
cents = 0;
}
else if ( cents != 0 && cents % 25 != cents) {
counter += round(cents / 25);
cents = cents % 25;
}
if (cents != 0 && cents % 10 == 0)
{
counter += round(cents / 10);
cents = cents % 10;
}
else if (cents != 0 && cents % 10 != cents)
{
counter += round(cents/10);
cents = cents % 10;
}
//cents = 6
if (cents != 0 && cents % 5 == 0)
{
counter += round(cents/5);
}
else if ( cents != 0 && cents % 5 != cents)
{
counter += round(cents/5);
cents = cents % 5;
}
else
{
//counter += cents;
}
counter += cents;
printf("%i\n", counter);
}