Answer to Question #168458 in C++ for Marco Antonio Tinoco

Question #168458

3.25.1: LAB: Exact change c++ Write a program with total change amount as an integer input, and output 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.



1
Expert's answer
2021-03-03T08:02:27-0500
#include <iostream>
using namespace std;
int main () {
    int quarters;   // Number of quarters, to be input by the user.
    int dimes;      // Number of dimes, to be input by the user.
    int nickels;    // Number of nickels, to be input by the user.
    int pennies;    // Number of pennies, to be input by the user. 
    
    double dollars; // Total value of all the coins, in dollars.
      
    /* Ask the user for the number of each type of coin. */
    
    cout << "Enter the number of quarters:  ";
    cin >> quarters;
    cout << "Enter the number of dimes:  ";
    cin >> dimes;
    cout << "Enter the number of nickels:  ";
    cin >> nickels;
    cout << "Enter the number of pennies:  ";
    cin >> pennies;
    
    /* Add up the values of the coins, in dollars. */
    dollars = (0.25 * quarters) + (0.10 * dimes) 
                          + (0.05 * nickels) + (0.01 * pennies); 
    cout << "The total in dollars is $\n";
    cout << dollars << " dolllars";
    return 0;
}




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