The following C++ program converts quarters, dimes and nickels to cents. It is assumed that you know the basic syntax of a C++ program.
In this article, you’ll learn:
- To convert quarters to cents in C++.
- To convert dimes to cents in C++.
- To convert nickel to cents in C++.
- Finally, to convert quarters, dimes and nickels to cents in C++.
We’ll use the step by step approach to understand the problem. To understand how to write a program to convert this into that in programming, you must know the relation between the quantities or the units.
Prerequisite knowledge to understand the program
- 25 cents make one quarter, i.e., 1 quarter = 25 cents.
- 10 cents make one dime, i.e., 1 dime = 10 cents.
- 5 cents make one nickel, i.e., 1 nickel = 5 cents.
Now, using this information, try to calculate how many cents are there in 3 quarters. Got the answer? Yes, 75 cents will be the answer. We got it using basic mathematics. 3 * 25 = 75 cents.
We’ll use this information and the basic syntax of a C++ program to convert quarter, dime and nickel to cents.
Step 1: Basic syntax of a C++ program
#include <iostream> using namespace std; int main() { /* Statements here */ return 0; }
Step 2: Creating variables to store values and taking input from the user
#include <iostream> using namespace std; int main() { int quarter, dime, nickel, cent; cout << "Enter the number of quarter, dime and nickel respectively: "; cin >> quarter>>dime>>nickel; //input from the user return 0; }
Step 2: Using the relations mentioned above to calculate number of cents
#include <iostream> using namespace std; int main() { int quarter, dime, nickel, cent; cout << "Enter the number of quarter, dime and nickel respectively: "; cin >> quarter>>dime>>nickel; cent = quarter*25 + dime*10 + nickel*5; //basic mathematics return 0; }
Step 3: Printing the calculated result(Complete program)
#include <iostream> using namespace std; int main() { int quarter, dime, nickel, cent; cout << "Enter the number of quarter, dime and nickel respectively: "; cin >> quarter>>dime>>nickel; cent = quarter*25 + dime*10 + nickel*5; // this will store the result into cent variable //to print the calculated value cout << "If there are " << quarter << " quarters " << dime << " dimes, \nand "<< nickel << " nickels, then the equivalent to cent is " << cent; cout<<"\n\n End of the Program"; return 0; }
That’s it. So this is how to create a C++ program that converts quarters, dimes, and nickels into cents.
Sample output:
Now before looking at the output, try to calculate the number of cents in 3 quarters, 4 dimes and 5 nickels manually on a paper or calculator.
It goes like, 3 quarters = 3 * 25 = 75 cents, 4 dimes = 4 * 10 = 40 dimes, and 5 nickels = 5 * 5 = 25 cents. That means a total of 75 + 40 + 25 = 140 cents. Now have a look at the sample output below to see if our program works fine.

That’s great. We did it. Now try to write C++ program that converts quarters into cents and let me know in the comments below.
What did we learn?
- C++ program to convert quarter, dime and nickel into cents.
- How to approach the solution of a C++ program step by step as a beginner.