Block of Code

Practical Examples for Programmers

  • Home
  • C++
  • Java
  • Visual Basic
  • Discrete Math
  • Ask a Question

Quarters Dimes and Nickels

Using C++, write a program that prompts the user to input a number of quarters, dimes and nickels. The program then outputs the total value of the coins in cents.

Write the Code:

/*
Project: Quarters Dimes and Nickels
Description: User inputs number of quarters, dimes and nickels.
Program calculates amount of change.
*/

#include <<iostream>>
using namespace std;

int main()
{
   int quarters, dimes, nickels = 0;
   float amount = 0;
   cout << "\nEnter number of quarters:";
   cin >> quarters;
   cout << "\nEnter number of dimes:";
   cin >> dimes;
   cout << "\nEnter number of nickels:";
   cin >> nickels;
   amount = (quarters * .25) + (dimes * .1) + (nickels * .05);
   cout << "\nTotal amount of change $" << amount;
   return 0;
}

Secondary Sidebar

This is the secondary sidebar

Copyright © 2025 · Metro Pro Theme on Genesis Framework · WordPress · Log in