Thread: c programming- Help needed writing code for coin calculation

  1. #1
    Registered User
    Join Date
    Nov 2012
    Posts
    2

    c programming- Help needed writing code for coin calculation

    hi there. i really need help in writing code for below case

    the output should be like

    how much change is owed? 0.32 (0.32 which is user input in dollar)
    Output:4

    Thought process:
    quater + nickel + penny +penny =$0.32.

    How to write code for this ???

    Todo:
     Prompt user for a monetary amount
     At each ‘step,’ return the biggest
    coin possible
     Keep track of:
    1. how many coins to be returned
    2. amount to be returned
     Print the final amount of coins

    Seriously, i dont know how to proceed.
    someone plz help

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,666
    Announcements - C Programming
    and
    A development process

    I suggest you practice giving yourself some change for some random amounts, say $0.42
    While you're looking at the amount, consider why exactly you chose a 'quarter' (what is the maths behind it).
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Nov 2012
    Posts
    2
    0.42 the coins owed is 5
    we should take a biggest coin possible for 0.42
    quarter(.25) + dime(.10) +nickel(.5) + penny(.1) +penny(.1)...
    quarter is the biggest possible
    if another quarter .25+.25=.50 which exceeds .42
    so picking next biggest possible dime .25+.10=.35 which doesnt exceed
    etc...

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,666
    OK, so what about $0.55, $0.66, $0.77, $0.88 and $0.99 ?

    I'm trying to get you to think about the steps involved.

    For example, keep subtracting x from y until y is less than x
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. need help with c-code for polynomial calculation
    By dreadkopp in forum C Programming
    Replies: 12
    Last Post: 12-22-2011, 10:09 PM
  2. writing good code is like writing an artistic expression
    By renzokuken01 in forum C Programming
    Replies: 5
    Last Post: 02-03-2011, 08:48 PM
  3. Replies: 2
    Last Post: 03-05-2009, 10:25 AM
  4. Help needed in writing a c++ program!
    By nightfallz in forum C++ Programming
    Replies: 3
    Last Post: 02-11-2009, 05:26 AM
  5. Urgent Help Needed In Writing Algorithm!!
    By Vikramnb in forum C++ Programming
    Replies: 1
    Last Post: 01-09-2009, 12:46 PM