# Thread: Problem with program.

1. ## 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. 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. 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. 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. Originally Posted by CommonTater
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. 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. 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. Originally Posted by CommonTater
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. Originally Posted by EmaZek
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. Originally Posted by CommonTater
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. Originally Posted by EmaZek
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