# Write a program with total change amount as an integer input that outputs the change using the fewest coins, one coin type per line. The coin types are dollars, quarters, dimes, nickels, and pennies. Use singular and plural coin names as appropriate, like 1 penny vs. 2 pennies.Ex: If the input is:0or less, the output is:no changeEx: If the input is:45the output is:1 quarter 2 dimesYour program must define and call the following function. Positions 0-4 of coinVals should contain the number of dollars, quarters, dimes, nickels, and pennies, respectively.void ExactChange(int userTotal, vector<int>& coinVals)#include <iostream>#include <vector> using namespace std;void ExactChange(int userTotal, vector<int>& coinVals) {if (penny == 1) {cout << penny << "penny" << endl;}if (penny > 1) {cout << penny << "pennies" << endl;}if (penny == 0) {cout << "no change" << endl;}}/* Define your function here */int main() {int inputVal;vector<int> changeAmount(5); cin >> inputVal;ExactChange(inputVal, changeAmount);/* Type your code here. Your code must call the function. */return 0;}Please help me with this problem using c++.

Question
2619 views

Write a program with total change amount as an integer input that outputs the change using the fewest coins, one coin type per line. The coin types are dollars, quarters, dimes, nickels, and pennies. Use singular and plural coin names as appropriate, like 1 penny vs. 2 pennies.

Ex: If the input is:

0

or less, the output is:

no change

Ex: If the input is:

45

the output is:

1 quarter 2 dimes

Your program must define and call the following function. Positions 0-4 of coinVals should contain the number of dollars, quarters, dimes, nickels, and pennies, respectively.
void ExactChange(int userTotal, vector<int>& coinVals)

#include <iostream>
#include <vector>
using namespace std;

void ExactChange(int userTotal, vector<int>& coinVals) {
if (penny == 1) {
cout << penny << "penny" << endl;
}
if (penny > 1) {
cout << penny << "pennies" << endl;
}
if (penny == 0) {
cout << "no change" << endl;
}
}
/* Define your function here */

int main() {
int inputVal;
vector<int> changeAmount(5);
cin >> inputVal;
ExactChange(inputVal, changeAmount);
/* Type your code here. Your code must call the function. */

return 0;
}

check_circle

star
star
star
star
star
1 Rating
Step 1

Completing the given C++ program so, that it can follow the given rubrics:

• Firstly, displaying a message to the user to enter the amount.
• Taking input of amount from user.
• In main method declaring a vector name changeAmount.
• Checking if the user entered value is zero then displaying a message to user that there is no change.
• If the user entered value is not zero, then calling changeAmount function.
• Calculating the change in changeAmount function and displaying change to user.
Step 2

Program code:

#include <iostream>

#include <vector>

using namespace std;

//defining the given method

void ExactChange(int userTotal, vector<int> &coinVals) {

//using reserving space

coinVals.reserve(5);

//checking for quarter, dimes, nickels, pennies etc.

coinVals[0] = userTotal / 100;

//using modulus operator

userTotal %= 100;

coinVals[1] = userTotal / 25;

//using modulus operator

userTotal %= 25;

coinVals[2] = userTotal / 10;

//using modulus operator

userTotal %= 10;

//using modulus operator

coinVals[3] = userTotal / 5;

//using modulus operator

userTotal %= 5;

coinVals[4] = userTotal;

}

//main method

int main() {

//declaring vector

vector<int> changeAmount(5);

//declaring value variable in integer

int inputVal;

//taking value of amount

cout<<"Enter amount: ";

cin>>inputVal;

//checking that value is equal to 0

if (inputVal <= 0) {

//if yes displaying the message to user that change is not available

cout<<"no change\n";

}

//otherwise

else

{

//displaying message to user your change

### Want to see the full answer?

See Solution

#### Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in