To say that an aglorithm works means that we tested it on some input values and verified that it gives us the right answer.
What input did you check the math with? How many kids were you assuming?
From my earlier post:
To prove toourselves that we really understand the task, let's say we have a family of 5: mother, father, and three kids. The father make $1500 per week. How much money pocket money does the wife and each kid get?
So, let's walk through this example with your code:
//salary input 1500.
salary = (salary/2); //now salary is 750, half went to house.
salary = (salary *1/3); //now salary is 250. This is how much we are saving.
salary = (salary *1/3); Now salary is 83.3333 Why?
salary = (salary *1/2); Now salary is 41.67. No, wrong answer.
System.out.println("Pocket money obtain by one parent: " + salary);
Now, lets forget the code, like I suggested, and do the problem.
The whole salary is 1500.
Half goes to the housr, so 750 is left.
One third gets saved, so 750 - 250 = 500 remains to dived as spending money.
At this point we realize that you were not dividing up the problem correctly. The first part of the problem is to determine how much spending money is left for the whole family. We just did that part now and you never did that in your program.
Now, how …