+ 1

Why is BlueJ is giving any answer the same value as I gave in input ?

I have been facing this problem since two months ago. I had written a program which I had declared the variables as 0 or 0.0 as mentioned in the question. When I had executed the program and gave the input(≠ 0), to my great amazement, it came the same result as input, which was very unexpectable . Later, by doing several experiments, I concluded that "It is not doing any operations which I have programmed it to do." How can I resolve it? Here are the codes(Please execute these codes in BlueJ Environment) : https://code.sololearn.com/c2OzIIWda3T2/?ref=app https://code.sololearn.com/c49gQqDr34Cf/?ref=app [Edited: I would like to thank "zemiak" and "~swim~" for their due efforts to make my program successful. I wanted to mark both of their answers as the best answer. But I was not able to do so. So, I marked neither of them as the best answer. What did they said is that I did "int/int(for percentage) * double", which was causing all the troubles. ]

23rd Aug 2019, 10:34 AM
GiantJupiter
GiantJupiter - avatar
4 Respostas
+ 1
yes, in camera if you use int / int * double you lost decimal part of double numbers, so result is different to your expects. use all numbers with decimal point so fix camera program: //d = 10 /100 * price; d = 10.0/100.0 * price; ... //gst = 6 /100 * dprice; gst = 6.0 /100.0 * dprice; then for input 10.0 you get 9.54 as result: Enter the printed price of digital camera: 10.0 The amount to be paid by the customer:9.54 I check it on BlueJ but I was able only compile it and run it manually in terminal with result 9.54 too
23rd Aug 2019, 11:30 PM
zemiak
+ 1
Thank you "zemiak" and "~swim~"!!!
24th Aug 2019, 9:22 AM
GiantJupiter
GiantJupiter - avatar
0
show the code
23rd Aug 2019, 10:58 AM
zemiak
0
I have edited in the description but please execute these in BlueJ, especially the "Camera" code, which is again giving catostrophic results.
23rd Aug 2019, 5:43 PM
GiantJupiter
GiantJupiter - avatar