-
Notifications
You must be signed in to change notification settings - Fork 11
/
Cash.c
40 lines (39 loc) · 751 Bytes
/
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
//Program based on Greedy Algorithm
//Minimze the number of coins in change as much as possible
#include <cs50.h>
#include <stdio.h>
#include <math.h>
int main(void)
{
int change = 0;
float owed;
//getting positive number
do
{
owed = get_float("Change owed: ");
}
while (owed < 0);
//converting the float or just my solution to deal with them
owed *= 100;
while (round(owed) >= 25)
{
owed -= 25;
change++;
}
while (round(owed) >= 10)
{
owed -= 10;
change++;
}
while (round(owed) >= 5)
{
owed -= 5;
change++;
}
while (round(owed) >= 1)
{
owed -= 1;
change++;
}
printf("%i\n", change);
}