|
|
|
||||||
|
The complete program code is given below :
In the program we declared the variables as double. We do this to get the correct results (results may be in decimal points) of the calculations. Look at the statement which calculates the discount. The statement is discount = amount * (15.0 / 100) ; Here in the above statement we write 15.0 instead of 15. If we write here 15 then the division 15 / 100 will be evaluated as integer division and the result of division (0.15) will be truncated and we get 0 and this will result the whole calculation to zero. So it is necessary to write at least one operand in decimal form to get the correct result by division and we should also declare the variables as float or double. We do the same in the line discount = amount * (10.0 / 100); A sample execution of the program is given below
|
|||||||
|
|
Previous |
TOC |
Next |
||||