Question
Write a program that prompts the user for a dollar amount (a positive integer), then displays the number of bills needed to add up to
Write a program that prompts the user for a dollar amount (a positive integer), then displays the number of bills needed to add up to the given amount. Only a single number needs to be displayed, however I wish to display all if possible. I must use bills of the following denominations: $100, $20, $10, $5, and $1. If the user enters a negative amount, loop back and re-prompt the user. The program should have a minimum of three functions. 1 function that computes the work, 1 function that re-prompts the user for bill amount, and the main function. The bills function that computes the work cannot print anything out.
Here is what I have so far. I know its not working but I would appreciate any help I can get. Thank you!
#include
int get_amount(); //function prototype int bills(); //function prototype
int main() {
int amountinputted; int amount; int hundred; int twenty; int ten; int five; int one;
get_amount();
bills();
printf("Number of $100 bills: %d ", bills(hundred)); printf("Number of $20 billss: %d ", bills(twenty)); printf("Number of $10 billsss: %d ", bills(ten)); printf("Number of $5 billssss: %d ", bills(five)); printf("Number of $1 billsssss: %d ", bills(one));
return 0; }
///////////////////////////////////////////////////
int get_amount() { int amountinputted; do { printf("Enter a positive amount: "); scanf("%d", &amountinputted); } while (amountinputted <= 0); return amountinputted; }
///////////////////////////////////////////////////
int bills (int amount) { int total; int hundred = 100; int twenty = 20; int ten = 10; int five = 5; int one = 1;
total = (int)amount/100; amount = amount-(total*100); total = (int)amount/20; amount = amount-(total*20); total = (int)amount/10; amount = amount-(10); total = (int)amount/5; amount = amount-(total*5); total = (int)amount/1; return amount;
// Other strategy... // int amount; // int hundred = 0; // int twenty = 0; // int ten = 0; // int five = 0; // int one = 0;
//hundred = amount / 100; // twenty = amount / 20; // ten = (amount - (20 * twenty)) / 10; // five = (amount - (20 * twenty) - 10) / 5; // one = (amount - (20 * twenty) - 10) / 1;
// return amount; }
OUTPUT:
Enter a positive amount: 123 Number of $100 bills: 2 Number of $20 billss: 0 Number of $10 billsss: 4 Number of $5 billssss: 0 Number of $1 billsssss: 3
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started