Create a program that continuously prompts the user for a number of dollars unti
ID: 3546502 • Letter: C
Question
Create a program that continuously prompts the user for a number of dollars until the user enters 0. Pass each entered amount to a conversion method that displays a breakdown of the passed amount into the fewest bills; in otherwords, the method calculates the number of 20s, 10s, 5s, and 1s needed.
PSEUDOCODE:
// Start
// Declarations
// num dollars
// output "Please enter the a whole dollar amount (no cents!). Input 0 to terminate: "
// input dollars
// while ( dollars <> 0)
// displayBills(dollars)
// output "Please enter the a whole dollar amount (no cents!). Input 0 to terminate: "
// input dollars
// endwhile
// Stop
//
//
//
// displayBills(num dollars)
// Declarations
// num ones
// num fives
// num tens
// num twenties
// num temp
// twenties = dollars / 20
// temp = dollars % 20
// tens = temp / 10
// temp = temp % 10
// fives = temp / 5
// ones = temp % 5
// output "The dollar amount of ", dollars, " can be represented by the following monetary denominations"
// output " Twenties: ", twenties
// output " Tens: ", tens
// output " Fives: ", fives
// output " Ones: ", ones
// return
Explanation / Answer
#include <iostream>
using namespace std;
void displayBills(int dollars);
int main()
{
int numDollars;
cout<<"Please enter the a whole dollar amount (no cents!). Input 0 to terminate: ";
cin>>numDollars;
while(numDollars!=0)
{
displayBills(numDollars);
cout<<"Please enter the a whole dollar amount (no cents!). Input 0 to terminate: ";
cin>>numDollars;
}
}
void displayBills(int dollars)
{
int temp=dollars;
int>
twenties = dollars / 20;
temp = dollars % 20;
tens = temp / 10;
temp = temp % 10;
fives = temp / 5;
ones = temp % 5;
cout<<"The dollar amount of ", dollars, " can be represented by the following monetary denominations ";
cout<<" Twenties: "<<twenties<<endl;
cout<<" Tens: "<<tens<<endl;
cout<<" Fives: "<<fives<<endl;
cout<<" Ones: "<<ones<<endl;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.