Write a program that allows the user to enter a number of quarters, dimes,and nickels and then outputs the monetary value of the coins in cents. For example, if the user enters 2 for the number of quarters, 3 for the number of dimes, and 1 for the number of nickels, then the program should output that the coins are worth 85 cents.
Program Code:
//Header file
#include <iostream>
using namespace std;
//main function
int main ( )
{
//Variable declaration
int number_of_quarters, number_of_dimes;
int number_of_nickels, total;
int quarters = 25;
int dimes = 10;
int nickels = 5;
//Prompt and read input from the keyboard
cout << "Enter the number of quarters:";
cin >> number_of_quarters;
cout << "Enter the number of dimes:";
cin >> number_of_dimes;
cout << "Enter the number of nickels:";
cin >> number_of_nickels;
//calculation
total = (quarters*number_of_quarters) +(dimes*
number_of_dimes) + (nickels* number_of_nickels);
//Display the result
cout << "Monetary value is " << total << " cents.\n";
return 0;
}
Output:
Enter the number of quarters:2
Enter the number of dimes:3
Enter the number of nickels:1
Monetary value is 85 cents.