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.
Re: Can Somebody Help me?
I updated the code(The first code i put was incorrect sorry T_T).
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;
instead of
Code :
Amnt5 = Amnt * 20;
Amnt1 = Amnt /20;
Amnt1 %= 20;
Amnt2 = Amnt5 / 10;
Amnt2 %= 10;
Amnt3 = Amnt /5;
Amnt3 %= 5;
Amnt4 = Amnt / 1;
Amnt4 %= 1;
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
Amnt = Integer.parseInt(Kehn.readLine());
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!