forked from harshitbansal373/hacktoberfest2020
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcash.c
More file actions
26 lines (22 loc) · 682 Bytes
/
cash.c
File metadata and controls
26 lines (22 loc) · 682 Bytes
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
// Dhananjay Yelwande
#include <stdio.h>
#include <math.h>
#include <cs50.h>
int main()
{
int cents;
do
{
// Accepts user input in decimals
float dollars = get_float("Owed change: ");
// Rounds cents to nearest penny
cents = round(dollars * 100);
}
while (cents <= 0);
// Conversion of user's inputted dollars
int quarters = cents / 25;
int dimes = (cents % 25) / 10;
int nickels = ((cents % 25) % 10) / 5;
int pennies = ((cents % 25) % 10) % 5;
printf("Quarters : %d\nDimes : %d\nNickels : %d\nPennies : %d\nTotal coins : %d\n",quarters,dimes,nickels,pennies, quarters + dimes + nickels + pennies);
}