Have you ever made a program where there is no fault that you can find in the coding you've made? One of the example of the program that I thought there was no fault in the coding and yet, when I run the program there is this one error that I just thought at that time was never an error. When I go through my coding for like a thousand time, there is no logic errors. I even ask my dad(FYI my dad is a programmer too.) to go through the coding. He too cannot find the errors. Here is part of the program that have an error:
An overview of what my program was intended to do. It was supposedly to count the amount of money a user have input into the vending machine and check the money inserted with the price of the drinks that the user have chosen.
if(price == 0.00)
inform.setText(" Thank you for using the vending machine. \n Hope to see you again. \n You have no more balance.");
else if(price <>
inform.setText("Thank you for using the vending machine. \n Hope to see you again.\n You have another RM " +twoDigits.format(price));
else if(price > 0.00)
inform.setText("You have input an insufficient amount of money in the vending machine. \n You have to input another RM " +twoDigits.format(price));
Anyone who read this would never find the logical problem. I am sure of it. After a hard time trying to debug this code, I have found that the compiler that I was using (BlueJ) have count the price not equals to 0.00 but it equals to 2.7755575615628914E-17 and when we set the value to be of two decimal format it will show that it is 0.00 but in reality it actually equals to 2.7755575615628914E-17. Therefore, when you have encountered such an error you should check back your program.
No comments:
Post a Comment