Question: Hi I have a program for this but i need it to express the amounts of each for example you have this many hundreds, fifties,

Hi I have a program for this but i need it to express the amounts of each for example you have this many hundreds, fifties, twenties, etc.

Write 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. Your function should return a -1 if the user enters an invalid amount of money, e.g. a negative amount. Otherwise, your function should return a 1, indicating a successful changing of money. Include the function written above in a working program. Make sure your function is called from main() and returns a value to main() correctly. Have main() use a cout statement to display the returned value.

#include

using namespace std;

int change(int value, int* hundreds, int* fifties, int* twenties, int* tens, int* fives, int* ones) { // invalid value if (value < 0) return -1;

// valid value *hundreds = value/100; value = value - (100* (*hundreds));

*fifties = value/50; value = value - (50* (*fifties));

*twenties = value/20; value = value - (50* (*twenties));

*tens = value/10; value = value - (50* (*tens));

*fives = value/5;

value = value - (50* (*fives));

*ones = value;

return 1; }

// main function int main() { int value, hundreds, fifties, twenties, tens, fives, ones; int result;

cout << "Enter an integer value for dollar amount: "; cin >> value;

result = change(value, &hundreds, &fifties, &twenties, &tens, &fives, &ones);

cout << "The returned value from change() function is: " << result << endl << endl;

return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!