-
Notifications
You must be signed in to change notification settings - Fork 0
/
cash.c
46 lines (39 loc) · 1.12 KB
/
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
#include <stdio.h>
#include <cs50.h>
#include <math.h>
int main(void)
{
float change = -1.00;
while (change < 0)
{
change = get_float("what's the amount owed?\n>>> ");
}
int cents = round(change*100);
printf("you're getting %i cents back", cents);
static const char *coins[] = {"quarters", "dimes", "nickels", "pennies"};
static const char *coin[] = {"quarter", "dime", "nickel", "penny"};
int till[4] = {25, 10, 5, 1};
int payout[4] = {0,0,0,0};
for (int i = 0; i<4; i++)
{
printf("\n\tDISPENSING COIN VALUE OF: %i\n", till[i]);
int coinS = cents/till[i];
printf("\tgive #%i coin\n", coinS);
payout[i] = coinS;
cents = cents - (coinS*till[i]);
printf("\t%i cents leftover\n", cents);
}
printf("\nAmount owed to customer:\n");
for (int i = 0; i<4; i++)
{
if (payout[i] == 1)
{
printf("\t%i %s\n", payout[i], coin[i]);
}
else if (payout[i] > 1)
{
printf("\t%i %s\n", payout[i], coins[i]);
}
}
return 0;
}