-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgreedy.c
53 lines (41 loc) · 907 Bytes
/
greedy.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
//how many coins need for change
#include <stdio.h>
#include <cs50.h>
#include <math.h>
int main(void)
{
float change_input;
int coin_count = 0;
printf("How much change is owed?:\n");
do
{
change_input = GetFloat();
if (change_input <= 0)
{
printf ("Boo it must be a positive number. How much change is owed?\n");
}
}
while (change_input <= 0);
int change_remind = roundf ((change_input * 100));
while (change_remind >= 25)
{
change_remind -= 25;
coin_count++;
}
while (change_remind >= 10)
{
change_remind -= 10;
coin_count++;
}
while (change_remind >= 5)
{
change_remind -= 5;
coin_count++;
}
while (change_remind >= 1)
{
change_remind -= 1;
coin_count++;
}
printf ("%d\n" , coin_count);
}