Microcontroller Embedded C Programming Lecture 90| ‘if-else-if’ ladder exercise

  • Post author:
  • Post category:Blog

 

‘if-else-if’ ladder exercise

 

 

 

In this article, let’s do one exercise using an if-else-if ladder.

Exercise:

Write a program to calculate the income tax payable of the user.  The tax is calculated as per the below table.

if else if ladder exercise
Figure 1. Tax calculation table

 

The formula to calculate the Tax is Tax payable = Income *(tax rate/100). Tax rate is given in Figure 1. 

For this application, your program has to first ask the user about the total income. So, you have to get the total income by the user, so then multiply with the appropriate tax rate to the income to calculate the tax payable, and then you can print the tax. I want you to code this exercise using if-else-if statements. 

How the output of this exercise looks like is shown in Figure 2 and Figure 3.

 

if else if ladder exercise
Figure 2. Output

 

First, it should ask the user to enter the total income, I type 1000 dollars, and it should give me the tax payable. In this case, it is 0.

 

If I type 100000, it should give the tax payable as $33000. 

if else if ladder exercise
Figure 3. Output

 

So, try to do this exercise, and in the following article, I will code for this exercise.

 

FastBit Embedded Brain Academy Courses

Click here: https://fastbitlab.com/course1

 

FastBitLab

The FastBit Embedded Brain Academy uses the power of internet to bring the online courses related to the field of embedded system programming, Real time operating system, Embedded Linux systems, etc at your finger tip with very low cost. Backed with strong experience of industry, we have produced lots of courses with the customer enrolment over 3000+ across 100+ countries.

Leave a Reply