-
Notifications
You must be signed in to change notification settings - Fork 10
/
cash.c
49 lines (39 loc) · 788 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
41
42
43
44
45
46
47
48
49
#include <cs50.h>
#include <stdio.h>
#include <math.h>
int main(void)
{
float cash;
//checks if cash is positive
do
{
cash = get_float("Change owed: ");
}
while (cash < 0);
//convert and rounds to an integer number
int cents = round(cash * 100);
int coins = 0;
//check if it is possible to decrease
while (cents >= 25)
{
cents = cents - 25;
//count the number of change coins
coins++;
}
while (cents >= 10)
{
cents = cents - 10;
coins++;
}
while (cents >= 5)
{
cents = cents - 5;
coins++;
}
while (cents >= 1)
{
cents = cents - 1;
coins++;
}
printf("%i\n", coins);
}