SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Walter Savitch ,julia Lobur
Chapter:
Introduction To Computers And C++ Programming
Exercise:
Programming Projects
Question:8 | ISBN:9780321531346 | Edition: 7

Question

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.

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

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.
0 0

Discussions

Post the discussion to improve the above solution.