Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Change code to write a function called make_change that is passed the number of

ID: 3625294 • Letter: C

Question

Change code to write a function called make_change that is passed the number of cents that was passed in and then "returns“ via a call by reference, the number of quarters, dimes nickels and pennies it is equivalent to (see code below).
DO NOT USE GLOBAL VARIABLES.

Problem
Write a program that tells what coins to give out for any amount of change from 1 cent to 99 cents. You should use one function called get_input, to get the input from the user and another function called make_change that uses a call-by-reference mechanism to “pass back” how many quarters, dimes, nickels and pennies are needed.
(Note you need to get 4 answers)

You should write a third function called display_results to actually do the printing to the screen. You may write other functions as well, if you like.

For example if the amount is 86 cents, then the input would be 86 and the output would be something like the following:
86 cents can be given as
3 quarters, 1 dime, 0 nickels and 1 penny

If it were 31 cents, your output should look like
31 cents can be given as
1 quarter, 0 dimes, 1 nickel and 1 penny

Include a loop that lets the user repeat this computation for new input values until the user says he wants to quit.

CODE
#include <iostream>
using namespace std;

void get_value(int coin_value, int &number, int &make_change);
void input(int &make_change);
void display_results(int &make_change);

int main()
{

int make_change;
int number;
char choice;

do
{
input(make_change);
display_results(make_change);
cout << "Would you like to run again? (Y/N)? ";
cin >> choice;
}while (choice == 'Y' || choice == 'y');

return 0;
}

void get_value(int coin_value, int &number, int &make_change)
{

number = make_change/coin_value;
make_change = make_change%coin_value;
}

void input( int &make_change)
{

cout << "Coins ";
cin >> make_change;
}

void display_results (int &make_change)
{

int number;

get_value(25, number, make_change);
cout << number << " quarters, ";
get_value(10, number,make_change);
cout << number << " dimes, ";
get_value (05, number, make_change);
cout << number << " nickels, ";
cout << "and " << make_change << " pennies ";
}


Explanation / Answer

please rate - thanks

this what you want??

#include <iostream>
using namespace std;

void get_value(int coin_value,int&,int&,int&,int&);
void input(int &make_change);
void display_results(int make_change);

int main()
{

int make_change;
int number;
char choice;

do
{
input(make_change);
display_results(make_change);
cout << "Would you like to run again? (Y/N)? ";
cin >> choice;
}while (choice == 'Y' || choice == 'y');

return 0;
}

void get_value(int coin_value, int &quarters,int &dimes,int &nickels,int &pennies)
{quarters=coin_value/25;
coin_value%=25;
dimes=coin_value/10;
coin_value%=10;
nickels=coin_value/5;
pennies=coin_value%5;
}

void input( int &make_change)
{
cout << "Coins ";
cin >> make_change;
}

void display_results (int make_change)
{
int quarters,dimes,nickels,pennies;
get_value(make_change,quarters,dimes,nickels,pennies);
cout << quarters << " quarters, ";
cout << dimes << " dimes, ";
cout << nickels << " nickels, ";
cout << "and " << pennies << " pennies ";
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote