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
Asked Nov 26, 2019
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;
}

Please help me with this problem using c++.

check_circle

Expert Answer

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: ";

    //reading input from user

    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

        cout<<"\n your cha...

Want to see the full answer?

See Solution

Check out a sample Q&A here.

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

Engineering

Computer Science

Programing Language

Related Computer Science Q&A

Find answers to questions asked by student like you
Show more Q&A
add
question_answer

Q: What are looping control structures in c? Explain with the help of program?

A: In a program, Loop control structure is used to execute a block of code a finite number of times unt...

question_answer

Q: Explain the difference in the C memory model between global and local variables. How is each allocat...

A: Variable :A variable is used in a program to store any data in the memory.The value stored in a vari...

question_answer

Q: Online Responder used to issue certificates to network devices, such as routers and switches. True...

A: Online responder (OR):A position service which allows customers to test the revocation status of a c...

question_answer

Q: I am working on writing a Java program that computes the total surface area of a rectangular prism l...

A: Rewriting the given program code, so, that it can obey the below given rubrics:Importing essential h...

question_answer

Q: DESCRIBE THE FIRST LAYER OF BLOCK CHAIN?

A: Daniel Drescher in Blockchain Basics defines blockchain as a two-layer software system; application ...

question_answer

Q: What are the SQL query commands to create the tables (attached) with appropriate attributes and data...

A: Primary key:A primary key, also referred to as a primary keyword, is a key in a relational database ...

question_answer

Q: Think of one of your Math homework. How can you use program to reveal the answer? Write a calculatio...

A: A program is to be created that uses at least 10 variables to calculate a problem. Let us consider a...

question_answer

Q: d. Explain the steps of the fetch-decode-execute cycle. Your explanation should include what is happ...

A: A program consists of collections of instructions encoded using the method of binary numbers. The fe...

question_answer

Q: Why c++ is object oriented language?

A: An Object-oriented language?An object-oriented language is an approach in which the program is focus...