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 882263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T12:24:02+00:00 2026-05-15T12:24:02+00:00

I need to break down the amounts on their respective bill/coin. The output is

  • 0

I need to break down the amounts on their respective bill/coin.

The output is somewhat like this:

So far, here is my code: (I made the last few codes a comment one ‘cos the
errors come from there)

  { 
  int x,y;

  printf("Enter input: ");
  scanf("%d",&x);

  y=x/1000;
  printf("\n# of $1000 bill: %d",y);
  x = x%1000;

  y=x/500;      
  printf("\n# of 4500 bill: %d",y);    
  x = (x%500);

  y=x/200;
  printf("\n#. of $200 bill: %d",y);    
  x = (x%200);

  y=x/100;
  printf("\n# of $100 bill: %d",y);    
  x = (x%100);

  y=x/50;
  printf("\n# of $50 bill: %d",y);    
  x = (x%50);

  y=x/20;
  printf("\n# of $20 bill: %d",y);    
  x = (x%20);

  y=x/10;
  printf("\n#. of $10 coin: %d",y);    
  x = (x%10);

  y=x/5;
  printf("\n#. of $5 coin: %d",y);    
  x = (x%5);

  y=x/1;
  printf("\n# of $1 coin: %d",y);    
  x = (x%1);


  getch();
  return 0;
  }

I hope you’ll help me out with this. :/

Thanks!

  • 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-05-15T12:24:03+00:00Added an answer on May 15, 2026 at 12:24 pm

    It’s a simple heuristic problem. You already have the right idea. For a start, if you want to use int (and that’s probably a good idea in your case to avoid fp-precision headaches and the need to use a separate fmod), you’ll have to scale the floating-point input and your modulo/divisors by 100. Also to cut down on some redundancy, consider using a function like:

    // returns number of units and subtracts unit_size * result
    // from val
    int units(int* val, int unit_size)
    {
        int num = *val / unit_size;
        *val %= unit_size;
        return num;
    }
    
    printf("No. of P1000 bill: %d\n",units(&x, 1000 * 100) );
    printf("No. of P500 bill: %d\n",units(&x, 500 * 100) );
    printf("No. of P200 bill: %d\n",units(&x, 200 * 100) );
    etc.
    

    That should cut down on redundant code a little bit. Maybe not worth getting too fancy for it and I suspect this is homework. Complete solution:

    // returns number of units and subtracts unit_size * result
    // from val
    int units(int* val, int unit_size)
    {
        int num = *val / unit_size;
        *val %= unit_size;
        return num;
    }
    
    int main()
    {
        printf("Enter input: ");
    
        float amount;
        scanf("%f",&amount);
        int x = (int)(amount * 100.0 + 0.5);
    
        printf("No. of P1000 bill: %d\n", units(&x, 1000 * 100) );
        printf("No. of P500 bill: %d\n", units(&x, 500 * 100) );
        printf("No. of P200 bill: %d\n", units(&x, 200 * 100) );
        printf("No. of P100 bill: %d\n", units(&x, 100 * 100) );
        printf("No. of P50 bill: %d\n", units(&x, 50 * 100) );
        printf("No. of P20 bill: %d\n", units(&x, 20 * 100) );
        printf("No. of P10 coin: %d\n", units(&x, 10 * 100) );
        printf("No. of P5 coin: %d\n", units(&x, 10 * 100) );
        printf("No. of P1 coin: %d\n", units(&x, 1 * 100) );
        printf("No. of 25 cents: %d\n", units(&x, 25) );
        printf("No. of 1 cent: %d\n", units(&x, 1) );
    
        return 0;
    }
    

    [Edit] If you have trouble understanding pointers, then just do it the way you wrote without using the units function but modify it accordingly to read in a float and multiply by 100 as in the example above.

    [Edit] Requested:

    int main()
    {
        printf("Enter input: ");
    
        float amount;
        scanf("%f",&amount);
        int x = (int)(amount * 100.0 + 0.5); // x stores the user input in cents
    
        int y = x / 100000; // 1000 dollars is 100,000 cents
        printf("\nNo. of P1000 bill: %d",y);
        x = x % 100000;
    
        ...
    
        y=x / 25; // we're working with cents, so 25 = 25 cents
        printf("\nNo. of 25 cents: %d",y);    
        x = (x % 25);
    
        ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone break down the syntax here. Please. I need to learn this ASAP.
I need to break apart a string that always looks like this: something --
I am trying to break down a string into an array. This code below
Suppose you are calling a function, where there's clearly a need to break down
Need to apply a filter to a file like this: TUPAC_0006:1:1:2554:2356#0/1 0 * 0
I just started work on a C# application. I need to break down a
I have a rather complex DELETE query that I need to break down into
I need to break down a binary number into 4 decimal digits using assembly.
I need to break down a date in python into: year, month, day and
In a script I have several functions that need to break down an SVN

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.