forked from kish-an/cs50
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cash.c
51 lines (44 loc) · 837 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
50
51
#include <stdio.h>
#include <cs50.h>
#include <math.h>
float get_positive_float(string question);
int main(void)
{
float dollars = get_positive_float("How much change are you owed? ");
int coins = round(dollars * 100);
int count = 0;
while (coins > 0)
{
if (coins >= 25)
{
coins -= 25;
count++;
}
else if (coins >= 10)
{
coins -= 10;
count++;
}
else if (coins >= 5)
{
coins -= 5;
count++;
}
else
{
coins--;
count++;
}
}
printf("%i\n", count);
}
float get_positive_float(string question)
{
float n;
do
{
n = get_float("%s", question);
}
while (n < 0);
return n;
}