forked from RaduStoian/Harvard-CS50-Problems
-
Notifications
You must be signed in to change notification settings - Fork 0
/
(week1) - cash.c
48 lines (38 loc) · 838 Bytes
/
(week1) - 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
#include <cs50.h>
#include <stdio.h>
#include <math.h>
int main(void)
{
//declaring variables for loops
int i, j, k, l;
// getting input
float input = get_float("Change owed:");
while (input < 0)
{
input = get_float("Change owed:");
}
//changing to integer
int change = round(input * 100);
// i = number of 25c coins
for (i = 0; change >= 25; i++)
{
change -= 25;
}
// j = number of 10c coins
for (j = 0; change >= 10; j++)
{
change -= 10;
}
// k = number of 5c coins
for (k = 0; change >= 5; k++)
{
change -= 5;
}
// l = number of 1c coins
for (l = 0; change >= 1; l++)
{
change -= 1;
}
int coins = i + j + k + l;
printf("%i\n", coins);
}