Answer to Question #11679 in C++ for Chad Dylan Cooper

Question #11679
Write a program that consists of a function named change() that has an integer parameter and six integer reference parameters named hundreds, fifties, twenties, tens, fives, and ones. The function is to consider the passed integer value as a dollar amount and convert the value into the fewest number of equivalent bills. Using the reference parameters, the function should alter the arguments in the calling function. For example, 1194 will be converted to 11 hundreds, 1 fifties, 2 twenties, 0 tens, 0 fives, and 4 ones.
1
Expert's answer
2012-07-12T08:36:45-0400
#include <iostream>

using namespace std;

void change(int amount,int &hundreds, int &fifties, int &twenties, int &tens, int &fives, int &ones);

int main()
{
int amount, hundreds, fifties, twenties, tens, fives, ones;
cout<<"Enter the amount of money: ";
cin>>amount;
change(amount,hundreds, fifties, twenties, tens, fives, ones);
cout <<amount<<" is "<< hundreds<<" hundreds, "<<fifties<<" fifties, "<<twenties<<" twenties, "<<tens<<" tens, "<<
fives<<" fives, "<<ones<<" ones.";
return 0;
}

void change(int amount, int &hundreds, int &fifties, int &twenties, int &tens, int &fives, int &ones)
{
hundreds = amount/100;
amount %= 100;
fifties = amount/50;
amount %= 50;
twenties = amount/20;
amount %= 20;
tens = amount/10;
amount %= 10;
fives = amount/5;
amount %= 5;
ones = amount;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS