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.
#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;
}
Comments
Leave a comment