The problem is in this line:
total=paise25/4 + paise50/2 + rs1 + 2*rs2;
When you divide an integer by another integer - you get an integer. If you want to get a floating point value - you should make this intention explicitly. For example:
total=paise25/4.0 + paise50/2.0 + rs1 + 2*rs2;
Note the .0 parts that I've added - they will make the difference.
manpreet
Best Answer
2 years ago
I am trying to write a C program to input number of coins for 25 paise, 50 paise, 1 rupee and 2 rupees and calculate total amount in rupees. This is my code. I am not getting the correct result.
For example for 5 coins of 25 paise, I should get Rs 1.25. But I am getting Rs 1.00. I am very new to C. Please indicate my mistake