Thread: calculating remainders

  1. #1
    nehal
    Guest

    calculating remainders

    hey guys i'm a little stuck.

    i've been told to design a program that reads a number from 5 to 55. and the program should calculate how many of each 5, 10, 20 coins will be returned.

    for example, if input is 50, the program will return 2x20 and 1x10. if input is 35, the program will return 1x20 1x10 1x5


    the program has to be modular in nature
    how do i do this?

    can someone give an example of how i can go about doing this?

    thanks

  2. #2
    THANK YOU KINDLY SIR Phenax's Avatar
    Join Date
    Mar 2011
    Posts
    74
    What is it that you need help with? Calculating remainders? Operators in C and C++ - Wikipedia, the free encyclopedia Check out the "modulo" operator.
    Quote Originally Posted by Plato
    Never discourage anyone...who continually makes progress, no matter how slow.

  3. #3
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    For example...

    The amount of 50
    How many "20" coins would it contain?

    50 / 20 This division will give the answer of 2. That's 2x20.
    50 - 2 * 20 = 10 are left.

    How many "10" coins?
    10 / 10 = 1. That's 1x10.

    10 - 1 * 10 = 0. No more.

  4. #4
    Third Eye Babkockdood's Avatar
    Join Date
    Apr 2010
    Posts
    352
    The modulo operator divides two integers and returns the remainder between them. This statement...

    Code:
    int x = (7 % 2);
    ...assigns x to the remainder of seven divided by two, which is one. You can only do this with integers, there's another function that does the same thing with floating-point numbers, I can't remember it off the top of my head.
    Quote Originally Posted by The Jargon File
    Microsoft Windows - A thirty-two bit extension and graphical shell to a sixteen-bit patch to an eight-bit operating system originally coded for a four-bit microprocessor which was written by a two-bit company that can't stand one bit of competition.

  5. #5
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    Quote Originally Posted by Babkockdood View Post
    there's another function that does the same thing with floating-point numbers, I can't remember it off the top of my head.
    The funciton is fmod. You have to include math.h (and maybe link the math library) to use it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Runtime problem
    By SantoshN in forum C Programming
    Replies: 2
    Last Post: 10-12-2010, 02:42 PM
  2. Calculating : high numbers
    By MiraX33 in forum C++ Programming
    Replies: 9
    Last Post: 06-08-2006, 11:08 PM
  3. Calculating CPU Usage
    By vitaliy in forum Linux Programming
    Replies: 3
    Last Post: 08-21-2005, 09:38 AM
  4. Recursion
    By Lionmane in forum C Programming
    Replies: 11
    Last Post: 06-04-2005, 12:00 AM
  5. Taking input while calculating
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 07-12-2002, 04:47 PM