Simple C program to find total amount of rupees from total number of coins.

Course Queries Syllabus Queries 2 years ago

0 2 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 16 Aug 2022, this text provides information on Syllabus Queries related to Course Queries. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (2)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer 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

#include 

//Q 7d 2011 7th paper Honours 2008 syllabus
int main()

{
int paise25, paise50, rs1, rs2;
double total;
printf("\n Number of coins of:\n\n");
printf(" 25 paise    = ");
scanf("%d",&paise25);
printf(" 50 paise   = ");
scanf("%d",&paise50);
printf(" 1 rupee = ");
scanf("%d",&rs1);
printf(" 2 rupee      = ");
scanf("%d",&rs2);

total=paise25/4 + paise50/2 + rs1 + 2*rs2;
//if(stat<40 || chemistry<40 || physics<40 || math<40 || c<40)

printf("\n Total amount in rupees: Rs %.02f\n",total);

return 0;
}
profilepic.png
manpreet 2 years ago

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.


0 views   0 shares

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.

tuteehub community

Join Our Community Today

Ready to take your education and career to the next level? Register today and join our growing community of learners and professionals.

tuteehub community