Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8533563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:59:22+00:00 2026-06-11T09:59:22+00:00

So, I am trying to build this program, where I am suppose to take

  • 0

So, I am trying to build this program, where I am suppose to take an input from a user which is a total amount and an amount which is the paid amount. Now, the balance should be broken down into $10, $5, $1, quarters, dimes and nickles. But the below program/code, tells me the total number of quarters, dimes, and nickles in the balance and not the remaining. For example . If the total amount is 5.76 and paid amount is $15 then it should show, zero $10, one $5, 4 $1, zero $.25, 2 $.10 , zero $.05 and four $.01 .

Please tell me whats wrong in the code here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T09:59:24+00:00Added an answer on June 11, 2026 at 9:59 am

    The easiest fix is to get the number as a float then multiplying it by 100 then saving it as int.

    #include <iostream>
    
    using namespace std;
    
    int main ( )
    {
        float userNUmber;
        int change, quarters, dimes, nickels, pennies; // declare variables
        cout <<"Enter the amount of money: ";
        cin >> userNUmber; // input the amount of change
        change = userNUmber * 100;
        quarters = change / 25; // calculate the number of quarters
        change = change % 25; // calculate remaining change needed
        dimes = change / 10; // calculate the number of dimes
        change = change % 10; // calculate remaining change needed
        nickels = change / 5; // calculate the number of nickels
        pennies = change % 5; // calculate pennies
    
        cout << "\nQuarters: " << quarters << endl; // display # of quarters
        cout << " Dimes: " << dimes << endl; // display # of dimes
        cout << " Nickels: " << nickels << endl; // display # of nickels
        cout <<" Pennies: " << pennies << endl; // display # of pennies
        system("Pause");
        return (0);
    }
    

    Also to do it in a loop is something like this

    #include <iostream>
    #include <vector>
    #include <string>
    using namespace std;
    
    
    int main ( )
    {
        float userNUmber;
        int change, quarters, dimes, nickels, pennies; // declare variables
    
        cout <<"Enter the amount of money: ";
        cin >> userNUmber; // input the amount of change
        change = userNUmber * 100;
    
        vector<int> coins(4, 0);
        coins[0] = 25; coins[1] = 10; coins[2] = 5; coins[3] = 1;
        vector<string> coinsName(4, "");
        coinsName[0] = "Quaters"; coinsName[1] = "Dimes"; coinsName[2] = "Nickels"; coinsName[3] = "Pennies";
    
        for(size_t i = 0; i < coins.size(); ++i)
        {
            int numberOfCoins = change / coins[i]; // calculate the number of quarters
            change = change % coins[i]; // calculate remaining change needed
            cout << coinsName[i] << ": " << numberOfCoins << endl; // display # of quarters
        }
        system("Pause");
        return (0);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to build in my Layout this kind of line: Total......................1000 I need
I'm trying to build a view that operators something similar to this: The user
I am trying to build a query which will do this: Lets say for
I'm trying to exploit my format string bug, which lies in this program: #include
I'm trying to build a program which can remove an single-colored border form an
I've built this program to read a user name from a file. It checks
I am trying to build a binary tree from a string input piped to
I'm new to android and trying to build this application As a user, I
I'm trying to build this layout: I have this at this time: http://jsfiddle.net/Gh6mB/12/ The
Trying to build openssl-fips-2.0 with NDK, before I was lucky found this link and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.