Thread: Problem with program.

  1. #1
    Registered User
    Join Date
    Apr 2011
    Posts
    5

    Smile Problem with program.

    HI guys.
    I need help with some program that i have to make.
    Please help tnx.

    It goes like this.
    Wrote down a program that outputs all combinations for euro € coins.

    n =it's input number and it's sum.
    m= it's input number and it's the value of how much coins to use to return sum n number.
    € coins are: 2€, 1€, 0,50€ 0,20€ 0,10€ 0,05€ 0,02€ 0,01€
    Example:

    n=1(€), m=4(max amount of coins to return):

    - 1 ---------> 1€
    - 0,50 0,50----> 1€
    - 0,50 0,20 0,20 0,10 ------>1€
    and so on.

    I don't rly know how to start. BrutForce i think it's not option HEHE

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Every C program starts like this....
    Code:
    int main (void)
      {
    
        return 0; }
    From there you fill in the blanks.... Look up the C modulous operator .. % . Your program will also have to divide and add...

    You can't code a solution until you understand the problem. Sit down with a pen and paper --yeah old school but still very effective-- work out the steps you have to perform to solve the problem. From there take out everything you don't absolutely need to get the right answer... and then you will be ready to start coding; once you understand the problem itself and how to solve it.

    Get your code as far along as you can... and if you run into problems, post it here (in code tags, please) and ask specific questions. I and likely several others will be happy to help so long as you are showing some intiative of your own.

  3. #3
    Registered User
    Join Date
    Apr 2011
    Posts
    5
    CommonTarer:
    I completely agree with you !!
    I rly tried to wrote down on a paper old sql! but i rly don't know the way to go .. i will try to make some code i hope any good.

  4. #4
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Beileve me, if you can't work the problem on paper... you don't understand it.

    When you make change, how do you do it?
    Think in little tiny steps... (I'm more familiar with Dollars than Euros, but the concepts are the same)

    Customer buys an item for $11.65 tenders $20.00...
    How much does he have coming back? ($8.35)...
    What's the biggest denomination I can hand him? ($5.00)
    How much do I owe him now? ($3.35)...
    What's the biggest denomination I can hand him? ($1.00 x 3)
    Now how much do I still owe him?
    and so on...

    Notice this has nothing whatsoever to do with C code... it's not "how to write the program?", it's "How to make change?"... First you need to understand the problem.
    Then you need to work out a way to solve the problem... then you write code.

    There is no programmer on this planet, no matter how good, who can write a solution to a problem they don't understand...

  5. #5
    Registered User
    Join Date
    Apr 2011
    Posts
    5
    Quote Originally Posted by CommonTater View Post
    Beileve me, if you can't work the problem on paper... you don't understand it.

    When you make change, how do you do it?
    Think in little tiny steps... (I'm more familiar with Dollars than Euros, but the concepts are the same)

    Customer buys an item for $11.65 tenders $20.00...
    How much does he have coming back? ($8.35)...
    What's the biggest denomination I can hand him? ($5.00)
    How much do I owe him now? ($3.35)...
    What's the biggest denomination I can hand him? ($1.00 x 3)
    Now how much do I still owe him?
    and so on...

    Notice this has nothing whatsoever to do with C code... it's not "how to write the program?", it's "How to make change?"... First you need to understand the problem.
    Then you need to work out a way to solve the problem... then you write code.

    There is no programmer on this planet, no matter how good, who can write a solution to a problem they don't understand...
    Yes i agree .
    And this part:

    Customer buys an item for $11.65 tenders $20.00...
    How much does he have coming back? ($8.35)...
    What's the biggest denomination I can hand him? ($5.00)
    How much do I owe him now? ($3.35)...
    What's the biggest denomination I can hand him? ($1.00 x 3)
    Now how much do I still owe him?
    and so on...

    I will try to make a code worke like this .. it's a good idea tnx ..

  6. #6
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Nope... don't do that... you are taking an idea that has been handed to you...
    How much will you learn from that?

    You still won't understand the problem in small steps and you can't do that by "borrowing" someone else's thoughts.

    No offense, but writing code is like 10% of the job and it's always the last thing you do.

    I showed you how to analyse the problem --by playing the role-- now it's up to you to work out your own solution and code it.

  7. #7
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    Brute force method. Yup. It's a simple calculation that proceeds forward for each coin denomination.

    About 20 years ago I have actually written the program which calculates bills and coins to be dispensed from automated teller machines. This was a pilot project where a bank was thinking about allowing customers to have exact change, including right down to pennies. Brute force was fast enough... even when I had to incorporate a limited number of denominations which could run out any time, and also work with a maximum slot size which limits the amount of bills that could fit. For example, customer asks for $100, and all that is left are $1 bills. Will 100x that amount of paper fit or will it jam up the machine? Is it reasonable to dispense 5 cent coins 200x ?

  8. #8
    Registered User
    Join Date
    Apr 2011
    Posts
    5
    Quote Originally Posted by CommonTater View Post
    Nope... don't do that... you are taking an idea that has been handed to you...
    How much will you learn from that?

    You still won't understand the problem in small steps and you can't do that by "borrowing" someone else's thoughts.

    No offense, but writing code is like 10% of the job and it's always the last thing you do.

    I showed you how to analyse the problem --by playing the role-- now it's up to you to work out your own solution and code it.

    Ok i will try again on paper and think something up.

  9. #9
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by EmaZek View Post
    Ok i will try again on paper and think something up.
    You may arrive back at where I left you... but the important thing is to learn the process... play the roll of the program and figure out what you need to do, how many times, and in what order.

    Please understand... I'm not trying to give you a hard time (despite appearances). These are essential skills for a programmer to master.

  10. #10
    Registered User
    Join Date
    Apr 2011
    Posts
    5
    Quote Originally Posted by CommonTater View Post
    You may arrive back at where I left you... but the important thing is to learn the process... play the roll of the program and figure out what you need to do, how many times, and in what order.

    Please understand... I'm not trying to give you a hard time (despite appearances). These are essential skills for a programmer to master.
    I understand if u belive me or not, because my professor at university is allways saying this. That the first thing you have to do is to understand the task, only then you do the programing part.
    The programing part is easy but if u don't understand the project then you can't programe it. That's a fact. And if someone gives you the answer how to solve it. It doesn't mean that you understand it and it doesn't help you learn more and think like programer.
    but i'm trying and i hope it will get better tnx for help .. i will poste something soon, i hope.

  11. #11
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by EmaZek View Post
    but i'm trying and i hope it will get better tnx for help .. i will poste something soon, i hope.
    Of course... this isn't something that just falls out of the sky for most people. It's a very different way of thinking than our normal day to day interractions. But you'll get there, I'm sure ... it's mostly a matter of not letting yourself boggle when confronted with something new.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. BIG problem-O with a C program
    By JohnMayer in forum C Programming
    Replies: 13
    Last Post: 07-20-2002, 03:41 PM
  2. program problem
    By stormswift in forum C Programming
    Replies: 4
    Last Post: 06-11-2002, 12:49 PM
  3. Program problem
    By Mick in forum C++ Programming
    Replies: 1
    Last Post: 02-26-2002, 07:41 AM
  4. Problem with program...
    By Screwz Luse in forum C Programming
    Replies: 4
    Last Post: 12-05-2001, 10:54 AM
  5. Problem Program
    By Cyber Kitten in forum C Programming
    Replies: 5
    Last Post: 11-13-2001, 06:02 PM