# Can Somebody Help me?

• July 11th, 2012, 09:47 AM
Jesirism
Can Somebody Help me?
I was Solving a worded java problem, this is the situation:
Write a class that calculates and displays the conversion of an entered number of peso into currency denominations - 20s, 10s, 5s, and 1s. Save the class as Dollars.java.

I think my code (on the top) have missed something
This is my another code:
import java.io.IOException;

public class Dollars {
public static void main(String[] args) throws IOException{

int Amnt,Amnt1,Amnt2,Amnt3,Amnt4,Amnt5;
System.out.println("Enter a value in dollar: ");
Amnt5 = Amnt * 20;

Amnt1 = Amnt /20;
Amnt1 %= 20;
Amnt2 = Amnt5 / 10;
Amnt2 %= 10;
Amnt3 = Amnt /5;
Amnt3 %= 5;
Amnt4 = Amnt / 1;
Amnt4 %= 1;

System.out.println(Amnt1);
System.out.println(Amnt2);
System.out.println(Amnt3);
System.out.println(Amnt4);

If i put 100 the result will be:
20s = 5
10s = 0
5s = 0
1s = 0

This is the problem, If i put 50 the result will be:
20s = 2
10s = 1
5s = 0
1s = 0

But my result is:
20s = 2
10s = 0
5s = 0
1s = 0

another, If i put 15 the result will be:
20s = 0
10s = 1
5s = 1
1s = 0

and my result is:
20s = 0
10s = 0
5s = 3
1s = 0

• July 11th, 2012, 10:27 PM
kindk12
Re: Can Somebody Help me?
I compiled and checked the result. The program is running perfectly fine. Let me explain what you program is actually doing. Suppose you wanted to know how much is 1 dollar in peso and you also wanted to know how much is 1 peso in dollar. This is the program that does the same things. if you enter 1 for both the input you can see how much is 1 dollar worth in peso and also how much is 1 peso worth in dollar. Thats all about it. Your program is good.
• July 12th, 2012, 06:05 AM
Jesirism
Re: Can Somebody Help me?
I updated the code(The first code i put was incorrect sorry T_T).
• July 12th, 2012, 05:51 PM
kindk12
Re: Can Somebody Help me?
First let me explain you what your program does. It taken be taken as a money counting machine. Suppose say in your country there are only money bill of 20, 10, 5 and 1. And say you want to know how many bills of 20, 10, 5 and 1 are there in a certain amount. For example if you entered 50, whats the possibility. It can have two 20 bills and one 10 bills. You might wonder you can also have five 10 that can make 50. But our program is not designed to in that way. This should solve your problem
This is what you need in your program.
Code :

```Amnt1 = Amnt/20; if(Amnt1 == 0) Amnt2 = Amnt/10; else {Amnt = Amnt - 20*Amnt1; Amnt2 = Amnt/10; } if(Amnt2 == 0) Amnt3 = Amnt/5; else { Amnt = Amnt - 10*Amnt2; Amnt3 = Amnt/5; } Amnt4 = Amnt - 5 * Amnt3;```
Code :

```Amnt5 = Amnt * 20;     Amnt1 = Amnt /20; Amnt1 %= 20; Amnt2 = Amnt5 / 10; Amnt2 %= 10; Amnt3 = Amnt /5; Amnt3 %= 5; Amnt4 = Amnt / 1; Amnt4 %= 1;```
• July 12th, 2012, 08:13 PM
Jesirism
Re: Can Somebody Help me?
Thanks! I compile your program and it works! all the results are correct. But my instructor wants a simple program(with no if statements T_T).
But i got an idea on your work

Amnt5 = Amnt % 20;
Amnt6 = Amnt % 10;

Amnt1 = Amnt /20;
Amnt1 %= 20;
Amnt2 = Amnt5 / 10;
Amnt2 %= 10;
Amnt3 = Amnt6 /5;
Amnt3 %= 5;
Amnt4 = Amnt / 1;
Amnt4 %= 1;

Same Result ^^ Problem Solved!