{"id":10977,"date":"2022-08-19T06:36:15","date_gmt":"2022-08-19T06:36:15","guid":{"rendered":"http:\/\/fastbitlab.com\/?p=10977"},"modified":"2023-08-26T09:41:42","modified_gmt":"2023-08-26T04:11:42","slug":"microcontroller-embedded-c-programming-lecture-91-if-else-if-ladder-exercise-solution","status":"publish","type":"post","link":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-91-if-else-if-ladder-exercise-solution\/","title":{"rendered":"Microcontroller Embedded C Programming Lecture 91| &#8216;if-else-if&#8217; ladder exercise solution"},"content":{"rendered":"<div class=\"boldgrid-section\" style=\"background-image: linear-gradient(to left, #eeeeee, #eeeeee);\" data-bg-color-1=\"#EEEEEE\" data-bg-color-2=\"#EEEEEE\" data-bg-direction=\"to left\">\n<div class=\"container\">\n<div class=\"row\" style=\"padding-top: 35px; padding-bottom: 0px; background-image: linear-gradient(to left, #eeeeee, #eeeeee);\" data-bg-color-1=\"#EEEEEE\" data-bg-color-2=\"#EEEEEE\" data-bg-direction=\"to left\">\n<div class=\"col-md-1 col-sm-12 col-xs-12 col-lg-1\">\n<div class=\"boldgrid-shortcode\" data-imhwpb-draggable=\"true\">\n\n<\/div>\n<p>&nbsp;<\/p>\n<\/div>\n<div class=\"col-md-10 col-sm-12 col-xs-12 col-lg-10\">\n<h1 class=\"\" style=\"text-align: center; font-size: 30px; border-width: 0px; line-height: 50px;\"><strong><span style=\"color: #333399;\">&#8216;if-else-if&#8217; ladder exercise solution<\/span><\/strong><\/h1>\n<div class=\"row bg-editor-hr-wrap\" style=\"border-width: 0px; margin-top: -25px;\">\n<div class=\"col-lg-12 col-md-12 col-xs-12 col-sm-12\">\n<div>\n<p>&nbsp;<\/p>\n<div class=\"bg-hr bg-hr-10 color2-color\" style=\"border-style: solid; border-width: 0px 0px 3px;\"><\/div>\n<p>&nbsp;<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">In this article, let&#8217;s code a calculating tax exercise. The exercise is<\/span><\/p>\n<p class=\"\" style=\"background-color: #062374; font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><em><span style=\"color: #ffff00;\"><strong>Write a program to calculate the income tax payable of the user. The tax is calculated as per the below table.<\/strong><\/span><\/em><\/p>\n<figure id=\"attachment_10980\" aria-describedby=\"caption-attachment-10980\" style=\"width: 623px\" class=\"wp-caption aligncenter\"><img fetchpriority=\"high\" decoding=\"async\" class=\"wp-image-10980\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/08\/Figure-1-3-1024x276.png\" alt=\"if else ladder in c\" width=\"623\" height=\"168\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-1-3-1024x276.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-1-3-300x81.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-1-3-768x207.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-1-3-600x162.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-1-3-1536x414.png 1536w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-1-3-200x54.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-1-3-400x108.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-1-3-800x216.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-1-3-1200x323.png 1200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-1-3.png 1692w\" sizes=\"(max-width: 623px) 100vw, 623px\" \/><figcaption id=\"caption-attachment-10980\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 1. Tax calculation Table<\/span><\/figcaption><\/figure>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">First, let&#8217;s create some variables. I create <\/span><b>income<\/b><span style=\"font-weight: 400;\">, <\/span><b>tax<\/b><span style=\"font-weight: 400;\">, <\/span><b>temp_income <\/b><span style=\"font-weight: 400;\">are variables.&nbsp; So, let&#8217;s stick to integers. I would use <\/span><span style=\"color: #008000;\"><b>uint64_t<\/b><\/span><span style=\"font-weight: 400;\"> to hold the income and tax variables. I think 64-bit width is sufficient to hold billions of dollars.<\/span><\/span><\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><b><span style=\"color: #008000;\">unit64_t<\/span> income;<\/b><\/span><\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><b><span style=\"color: #008000;\">uint64_t<\/span> tax;<\/b><\/span><\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">So, I would use a <\/span><span style=\"color: #800080;\"><b>double<\/b><\/span><span style=\"font-weight: 400;\"> to create a temporary variable\u2192 <\/span><b><span style=\"color: #800080;\">double<\/span> temp_income;<\/b><\/span><\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">First, let&#8217;s ask the user to enter the income. So, <\/span><b><span style=\"color: #800080;\">printf<\/span><span style=\"color: #333399;\">(&#8220;Enter your total income:&#8221;)<\/span>;<\/b><\/span><\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">After that, I will read the user input into the temporary income variable. <\/span><b><span style=\"color: #800080;\">scanf<\/span>(<span style=\"color: #333399;\">\u201c%lf\u201d<\/span>,&amp;temp_income); <\/b><span style=\"font-weight: 400;\">(For double I use <\/span><span style=\"color: #333399;\"><b>%lf<\/b><\/span><span style=\"font-weight: 400;\">).&nbsp;<\/span><\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">And after that, I would store this temporary income into the income. The user may enter a real number, and he can break the application.&nbsp; Because I am just storing the integer part.<\/span><\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Here, income is of type uint_64, and temp_income is type double. So, the compiler may issue some warning here. That&#8217;s why it&#8217;s better to typecast temp_income into uint64_t.&nbsp;<\/span><\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><b>income = (<span style=\"color: #339966;\">uint64_t<\/span>) temp_income<\/b><span style=\"font-weight: 400;\"> is done just to extract the integer part. Because the user may enter a real number, and he can break the application. That&#8217;s why I&#8217;m taking the input as a real number and, after that, just taking the integer part.&nbsp;&nbsp;<\/span><\/span><\/p>\n<pre class=\"color-5-text-contrast color5-background-color\" style=\"font-size: 12px; box-shadow: #cecece 0px 0px 0px 0px;\"><span style=\"color: #ff99cc;\">int<\/span> main(void)\r\n{\r\n\r\n   <span style=\"color: #008000;\">uint64_t<\/span> income;\r\n <span style=\"color: #008000;\">  uint64_t<\/span> tax;\r\n\r\n  <span style=\"color: #ff99cc;\"> double<\/span> temp_income;\r\n\r\n  <span style=\"color: #ff00ff;\"> printf<\/span>(\"Enter your total income:\");\r\n  <span style=\"color: #ff00ff;\"> scanf<\/span>(\"%lf\",&amp;temp_income);\r\n\r\n   income = (<span style=\"color: #008000;\">uint64_t<\/span>) temp_income;<\/pre>\n<div><\/div>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Let&#8217;s start comparing. if(income &lt;= 9525), then tax = 0.&nbsp;<\/span><\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">How do you do the following comparison? <\/span><\/span><\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">You use <\/span><b><span style=\"color: #e04646;\">else<\/span>, <\/b><span style=\"font-weight: 400;\">or you use <\/span><span style=\"color: #e04646;\"><b>else if<\/b><\/span><span style=\"font-weight: 400;\">. If you use<\/span><span style=\"color: #e04646;\"><b> else<\/b><\/span><span style=\"font-weight: 400;\">, again, you have to open the flower bracket and use<\/span><span style=\"color: #e04646;\"><b> if<\/b><\/span><span style=\"font-weight: 400;\"> condition here for further comparison. You can use it<\/span><span style=\"color: #e04646;\"><b> else<\/b><\/span><span style=\"font-weight: 400;\">, no problem. So, we can solve this exercise by using an <span style=\"color: #333399;\"><a style=\"color: #333399;\" href=\"http:\/\/fastbitlab.com\/microcontroller-embedded-c-programming-lecture-89-if-else-if-ladder-statements\/\">if-else-if ladder<\/a><\/span>. So, instead of using <\/span><span style=\"color: #e04646;\"><b>else<\/b><\/span><span style=\"font-weight: 400;\">, you can evaluate another expression using <\/span><span style=\"color: #e04646;\"><b>else if<\/b><\/span><span style=\"font-weight: 400;\">.&nbsp;<\/span><\/span><\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"color: #e04646;\"><b>else<\/b><\/span><span style=\"font-weight: 400;\"> space <\/span><span style=\"color: #e04646;\"><b>if<\/b><\/span><span style=\"font-weight: 400;\">, open the parentheses for another expression. Another expression depends upon our work.&nbsp;<\/span><\/span><\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">Here, another expression is we have to compare the income between 9525 to 38700.<\/span> <\/span><\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">How do you do that? <\/span><\/span><\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">For this, we have to use relational operators like lesser than, greater than. If income is greater than 9525(this is, let&#8217;s keep this in parentheses) and logical-AND(&amp;&amp;) income is less than or equal to 38,700. And after that, let&#8217;s open the body of the else if block (open the curly brace). In this case, tax = income * 0.12. <\/span><\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Let\u2019s explain else if statement once again. This is what we did, shown in Figure 2.&nbsp;<\/span><\/p>\n<figure id=\"attachment_10982\" aria-describedby=\"caption-attachment-10982\" style=\"width: 579px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"wp-image-10982\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/08\/Figure-3-2-1024x210.png\" alt=\"if else ladder in c\" width=\"579\" height=\"119\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-3-2-1024x210.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-3-2-300x61.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-3-2-768x157.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-3-2-600x123.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-3-2-1536x315.png 1536w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-3-2-200x41.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-3-2-400x82.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-3-2-800x164.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-3-2-1200x246.png 1200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-3-2.png 1577w\" sizes=\"(max-width: 579px) 100vw, 579px\" \/><figcaption id=\"caption-attachment-10982\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 2. else if statement<\/span><\/figcaption><\/figure>\n<p class=\"\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">Open the parentheses of the<\/span><span style=\"color: #e04646;\"><b> else if<\/b><\/span><span style=\"font-weight: 400;\"> and <\/span><b>(income &gt; 9525) &amp;&amp; (income &lt;= 38700)<\/b><span style=\"font-weight: 400;\"> is a compound expression, and this is a logical expression. Why? Because, here is a logical-AND(&amp;&amp;); income&gt; 9525 and income &lt;= 38700 is a sub expression. Let me call expression1, and another sub expression let me call expression2.<\/span><\/span><\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">First, the (income &gt; 9525) sub expression will be evaluated because that is inside the parentheses. So, if you start evaluating from left to right. This evaluation is true, after that, (income &lt;= 38700) expression will be evaluated. This also turns out to be true. So, <\/span><b>True &amp;&amp; True<\/b><span style=\"font-weight: 400;\"> means the whole expression turns out to be<\/span><b> true<\/b><span style=\"font-weight: 400;\">. That&#8217;s why tax = income * 0.12; the statement will be executed in that case<\/span><span style=\"font-weight: 400;\">.&nbsp;&nbsp;<\/span><\/span><\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">If either one of these expressions turns out to be false, then the tax = income * 0.12 statement will not be executed.<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">So similarly, we can use one more <\/span><span style=\"color: #e04646;\"><b>else if<\/b><\/span><span style=\"font-weight: 400;\"> for our next comparison. In this case, if income is greater than 38700 and lesser than or is equal to 82500, in that case tax = income * 0.22.&nbsp;<\/span><\/span><\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">And again, you have to use one more <\/span><span style=\"color: #e04646;\"><b>else if<\/b><\/span><span style=\"font-weight: 400;\">. In this case, if income is greater than 82500, then tax = income * 0.32. And tax = tax + 1000 or you can also write in a shorthand notation tax += 1000.<\/span><\/span><\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">And after that, let&#8217;s print the tax in dollars. So, use the printf statement. <\/span><b><span style=\"color: #800080;\">printf<\/span>(<span style=\"color: #333399;\">&#8220;Tax payable: $%I64u\\n&#8221;,<\/span> tax)<\/b><span style=\"font-weight: 400;\">, Here I would use &#8216;u&#8217; because all tax and income calculations are always positive. Income and tax cannot be negative. That&#8217;s why tax payable is always unsigned. <\/span><\/span><\/p>\n<pre class=\"color-5-text-contrast color5-background-color\" style=\"font-size: 12px; box-shadow: #cecece 0px 0px 0px 0px;\"><span style=\"color: #ff99cc;\">if<\/span>(income &lt;= 9525){\r\n&nbsp; &nbsp; tax = 0;\r\n}<span style=\"color: #ff99cc;\">else if<\/span>( (income &gt; 9525) &amp;&amp; (income &lt;= 38700) ){\r\n&nbsp; &nbsp; tax = income * 0.12;\r\n}<span style=\"color: #ff99cc;\">else if<\/span>((income &gt; 38700) &amp;&amp; (income &lt;= 82500)){\r\n&nbsp; &nbsp; tax = income * 0.22;\r\n}<span style=\"color: #ff99cc;\">else if<\/span>(income &gt; 82500){\r\n&nbsp; &nbsp; tax = income * 0.32;\r\n    tax = tax + 1000;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  <span style=\"color: #008000;\"> \/\/tax += 1000;<\/span>\r\n}\r\n\r\n<span style=\"color: #ff00ff;\">printf<\/span>(\"Tax payable : $%I64u\\n\",tax );\r\n\r\n}<\/pre>\n<p class=\"\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">&nbsp;<\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Let&#8217;s see the output. Enter your total income, and I enter 9000. It shows tax payable is $0.&nbsp;<\/span><\/p>\n<figure id=\"attachment_10984\" aria-describedby=\"caption-attachment-10984\" style=\"width: 656px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"wp-image-10984\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/08\/Figure-5-1.png\" alt=\"if else ladder in c\" width=\"656\" height=\"188\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-5-1.png 942w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-5-1-300x86.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-5-1-768x220.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-5-1-600x172.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-5-1-940x270.png 940w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-5-1-200x57.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-5-1-400x115.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-5-1-800x229.png 800w\" sizes=\"(max-width: 656px) 100vw, 656px\" \/><figcaption id=\"caption-attachment-10984\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 3. Output<\/span><\/figcaption><\/figure>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Here I enter total income as 125000. It shows the tax payable is $41000.<\/span><\/p>\n<figure id=\"attachment_10985\" aria-describedby=\"caption-attachment-10985\" style=\"width: 605px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-10985 \" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/08\/Figure-6-1.png\" alt=\"Figure 6. Output\" width=\"605\" height=\"168\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-6-1.png 795w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-6-1-300x83.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-6-1-768x213.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-6-1-600x167.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-6-1-200x56.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-6-1-400x111.png 400w\" sizes=\"(max-width: 605px) 100vw, 605px\" \/><figcaption id=\"caption-attachment-10985\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 4. Output<\/span><\/figcaption><\/figure>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Let&#8217;s try with some real numbers. I entered 125000.888. It shows the correct output.<\/span><\/p>\n<figure id=\"attachment_10986\" aria-describedby=\"caption-attachment-10986\" style=\"width: 573px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-10986\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/08\/Figure-7-1.png\" alt=\"'if-else-if' ladder exercise solution\" width=\"573\" height=\"145\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-7-1.png 897w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-7-1-300x76.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-7-1-768x194.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-7-1-600x152.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-7-1-200x51.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-7-1-400x101.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-7-1-800x202.png 800w\" sizes=\"(max-width: 573px) 100vw, 573px\" \/><figcaption id=\"caption-attachment-10986\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 5. Output<\/span><\/figcaption><\/figure>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Now, what happens if a user enters a negative number? So there is a problem, as shown in Figure 6. So, you have to make sure that negative numbers are not allowed.&nbsp;<\/span><\/p>\n<figure id=\"attachment_10987\" aria-describedby=\"caption-attachment-10987\" style=\"width: 580px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-10987\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/08\/Figure-8-1.png\" alt=\"if else ladder in c\" width=\"580\" height=\"161\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-8-1.png 781w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-8-1-300x83.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-8-1-768x213.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-8-1-600x167.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-8-1-200x56.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-8-1-400x111.png 400w\" sizes=\"(max-width: 580px) 100vw, 580px\" \/><figcaption id=\"caption-attachment-10987\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 6. Output<\/span><\/figcaption><\/figure>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">How do you do that?<\/span><\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">We can solve this problem very easily.&nbsp; Here, if(temp_income&nbsp; &lt;&nbsp; 0), then you have to print \u201cincome cannot be negative\u201d. Here you have to exit the application. So, I would call wait_for_user_input(), and I would just exit so return 0, as shown below.<\/span><\/p>\n<pre class=\"color-5-text-contrast color5-background-color\" style=\"font-size: 12px; box-shadow: #cecece 0px 0px 0px 0px inset;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\"><span style=\"color: #ff99cc;\">int<\/span> main(void)\r\n{\r\n\r\n<span style=\"color: #008000;\">uint64_t<\/span> income;\r\n<span style=\"color: #008000;\"> uint64_t<\/span> tax;\r\n\r\n<span style=\"color: #ff99cc;\"> double<\/span> temp_income;\r\n\r\n<span style=\"color: #ff00ff;\"> printf<\/span>(\"Enter your total income:\");\r\n<span style=\"color: #ff00ff;\"> scanf<\/span>(\"%lf\",&amp;temp_income);\r\n\r\n<span style=\"color: #ff99cc;\"> if<\/span>(temp_income &lt; 0){\r\n&nbsp; &nbsp; &nbsp;<span style=\"color: #ff00ff;\">printf<\/span>(\"Income cannot be -ve\\n\");\r\n&nbsp; &nbsp; &nbsp;wait_for_user_input();\r\n&nbsp; &nbsp; &nbsp;<span style=\"color: #ff99cc;\">return<\/span> 0;\r\n}\r\n\r\nincome = (<span style=\"color: #008000;\">uint64_t<\/span>) temp_income;<\/pre>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Now let&#8217;s see the output. Let&#8217;s try with a negative number. I enter total income is -4500000, it prints \u201cIncome cannot be -ve\u201d. That&#8217;s how you solve the issue. Now it works.&nbsp;<\/span><\/p>\n<figure id=\"attachment_10989\" aria-describedby=\"caption-attachment-10989\" style=\"width: 658px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-10989\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/08\/Figure-10.png\" alt=\"exercise solution\" width=\"658\" height=\"181\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-10.png 927w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-10-300x83.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-10-768x211.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-10-600x165.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-10-200x55.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-10-400x110.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-10-800x220.png 800w\" sizes=\"(max-width: 658px) 100vw, 658px\" \/><figcaption id=\"caption-attachment-10989\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 7. Output<\/span><\/figcaption><\/figure>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">Please note that here there is no <\/span><span style=\"color: #e04646;\"><b>else<\/b><\/span><span style=\"font-weight: 400;\"> block. That is optional. For this application, that is optional.&nbsp;<\/span><\/span><\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">Even if you can implement the <\/span><span style=\"color: #e04646;\"><b>else<\/b><\/span><span style=\"font-weight: 400;\"> block with the<\/span><b> semicolon,<\/b><span style=\"font-weight: 400;\"> that is, NOP(no operation). You can use the else block at the end, as shown below.<\/span><\/span><\/p>\n<pre class=\"color-5-text-contrast color5-background-color\" style=\"font-size: 12px; box-shadow: #cecece 0px 0px 0px 0px inset;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\"><span style=\"color: #ff99cc;\">if<\/span>(income &lt;= 9525){\r\n&nbsp; &nbsp; tax = 0;\r\n}<span style=\"color: #ff99cc;\">else if<\/span>( (income &gt; 9525) &amp;&amp; (income &lt;= 38700) ){\r\n&nbsp; &nbsp; tax = income * 0.12;\r\n}<span style=\"color: #ff99cc;\">else if<\/span>((income &gt; 38700) &amp;&amp; (income &lt;= 82500)){\r\n&nbsp; &nbsp; tax = income * 0.22;\r\n}<span style=\"color: #ff99cc;\">else if<\/span>(income &gt; 82500){\r\n&nbsp; &nbsp; tax = income * 0.32;\r\ntax = tax + 1000;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style=\"color: #008000;\"> \/\/tax += 1000;<\/span>\r\n}<span style=\"color: #ffff00;\">else{<\/span>\r\n<span style=\"color: #ffff00;\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;;<span style=\"color: #008000;\">\/\/NOP<\/span><\/span>\r\n<span style=\"color: #ffff00;\">}<\/span>\r\n\r\n<span style=\"color: #ff00ff;\">printf<\/span>(\"Tax payable : $%I64u\\n\",tax );\r\n\r\n}<\/pre>\n<p class=\"\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">So, if none of those expressions are true, then at the end, it will come to the else block. And that is NOP.&nbsp;<\/span><\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400;\"><span style=\"color: #000000;\">But that won&#8217;t happen in our case because (income &gt; 82500) this expression will be evaluated as true.<\/span><\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"font-size: 20px; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; line-height: 28px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #333399;\"><b>FastBit Embedded Brain Academy Courses<\/b><\/span><\/p>\n<p class=\"\" style=\"font-size: 17px; border-width: 0px;\"><span style=\"color: #000000;\">C<span style=\"font-weight: 400;\"><span style=\"color: #000000;\">lick here:<\/span>&nbsp;<\/span><\/span><span style=\"color: #0000ff;\"><a style=\"color: #0000ff; text-decoration: underline;\" href=\"http:\/\/fastbitlab.com\/course1\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">https:\/\/fastbitlab.com\/course1<\/span><\/a><\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; &#8216;if-else-if&#8217; ladder exercise solution &nbsp; &nbsp; In this article, let&#8217;s code a calculating tax exercise. The exercise is Write a program to calculate the income tax payable of the user. The tax is calculated as per the below table. &nbsp; First, let&#8217;s create some variables. I create income, tax, temp_income are variables.&nbsp; So, let&#8217;s [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":10981,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ocean_post_layout":"","ocean_both_sidebars_style":"","ocean_both_sidebars_content_width":0,"ocean_both_sidebars_sidebars_width":0,"ocean_sidebar":"0","ocean_second_sidebar":"0","ocean_disable_margins":"enable","ocean_add_body_class":"","ocean_shortcode_before_top_bar":"","ocean_shortcode_after_top_bar":"","ocean_shortcode_before_header":"","ocean_shortcode_after_header":"","ocean_has_shortcode":"","ocean_shortcode_after_title":"","ocean_shortcode_before_footer_widgets":"","ocean_shortcode_after_footer_widgets":"","ocean_shortcode_before_footer_bottom":"","ocean_shortcode_after_footer_bottom":"","ocean_display_top_bar":"default","ocean_display_header":"default","ocean_header_style":"","ocean_center_header_left_menu":"0","ocean_custom_header_template":"0","ocean_custom_logo":0,"ocean_custom_retina_logo":0,"ocean_custom_logo_max_width":0,"ocean_custom_logo_tablet_max_width":0,"ocean_custom_logo_mobile_max_width":0,"ocean_custom_logo_max_height":0,"ocean_custom_logo_tablet_max_height":0,"ocean_custom_logo_mobile_max_height":0,"ocean_header_custom_menu":"0","ocean_menu_typo_font_family":"0","ocean_menu_typo_font_subset":"","ocean_menu_typo_font_size":0,"ocean_menu_typo_font_size_tablet":0,"ocean_menu_typo_font_size_mobile":0,"ocean_menu_typo_font_size_unit":"px","ocean_menu_typo_font_weight":"","ocean_menu_typo_font_weight_tablet":"","ocean_menu_typo_font_weight_mobile":"","ocean_menu_typo_transform":"","ocean_menu_typo_transform_tablet":"","ocean_menu_typo_transform_mobile":"","ocean_menu_typo_line_height":0,"ocean_menu_typo_line_height_tablet":0,"ocean_menu_typo_line_height_mobile":0,"ocean_menu_typo_line_height_unit":"","ocean_menu_typo_spacing":0,"ocean_menu_typo_spacing_tablet":0,"ocean_menu_typo_spacing_mobile":0,"ocean_menu_typo_spacing_unit":"","ocean_menu_link_color":"","ocean_menu_link_color_hover":"","ocean_menu_link_color_active":"","ocean_menu_link_background":"","ocean_menu_link_hover_background":"","ocean_menu_link_active_background":"","ocean_menu_social_links_bg":"","ocean_menu_social_hover_links_bg":"","ocean_menu_social_links_color":"","ocean_menu_social_hover_links_color":"","ocean_disable_title":"default","ocean_disable_heading":"default","ocean_post_title":"","ocean_post_subheading":"","ocean_post_title_style":"","ocean_post_title_background_color":"","ocean_post_title_background":0,"ocean_post_title_bg_image_position":"","ocean_post_title_bg_image_attachment":"","ocean_post_title_bg_image_repeat":"","ocean_post_title_bg_image_size":"","ocean_post_title_height":0,"ocean_post_title_bg_overlay":0.5,"ocean_post_title_bg_overlay_color":"","ocean_disable_breadcrumbs":"default","ocean_breadcrumbs_color":"","ocean_breadcrumbs_separator_color":"","ocean_breadcrumbs_links_color":"","ocean_breadcrumbs_links_hover_color":"","ocean_display_footer_widgets":"default","ocean_display_footer_bottom":"default","ocean_custom_footer_template":"0","ocean_post_oembed":"","ocean_post_self_hosted_media":"","ocean_post_video_embed":"","ocean_link_format":"","ocean_link_format_target":"self","ocean_quote_format":"","ocean_quote_format_link":"post","ocean_gallery_link_images":"off","ocean_gallery_id":[],"footnotes":""},"categories":[8],"tags":[16],"class_list":["post-10977","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog","tag-microcontroller-embedded-c-programming","entry","has-media"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Calculating Income Tax Using &#039;if-else-if&#039; Ladder in C: Solution &amp; Explanation<\/title>\n<meta name=\"description\" content=\"Income tax calculation using a &#039;if-else-if&#039; ladder in C programming. The step-by-step solution, variable handling, and logical expressions.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-91-if-else-if-ladder-exercise-solution\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Calculating Income Tax Using &#039;if-else-if&#039; Ladder in C: Solution &amp; Explanation\" \/>\n<meta property=\"og:description\" content=\"Income tax calculation using a &#039;if-else-if&#039; ladder in C programming. The step-by-step solution, variable handling, and logical expressions.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-91-if-else-if-ladder-exercise-solution\/\" \/>\n<meta property=\"og:site_name\" content=\"FastBit EBA\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/fastbiteba\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-08-19T06:36:15+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-08-26T04:11:42+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-2-3.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1199\" \/>\n\t<meta property=\"og:image:height\" content=\"491\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"FastBitLab\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@fastbiteba\" \/>\n<meta name=\"twitter:site\" content=\"@fastbiteba\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"FastBitLab\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-91-if-else-if-ladder-exercise-solution\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-91-if-else-if-ladder-exercise-solution\\\/\"},\"author\":{\"name\":\"FastBitLab\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#\\\/schema\\\/person\\\/e32b38e733a0d76ffa7e6bc998652e5d\"},\"headline\":\"Microcontroller Embedded C Programming Lecture 91| &#8216;if-else-if&#8217; ladder exercise solution\",\"datePublished\":\"2022-08-19T06:36:15+00:00\",\"dateModified\":\"2023-08-26T04:11:42+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-91-if-else-if-ladder-exercise-solution\\\/\"},\"wordCount\":1077,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-91-if-else-if-ladder-exercise-solution\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/Figure-2-3.png\",\"keywords\":[\"Microcontroller Embedded C programming Lectures\"],\"articleSection\":[\"Blog\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-91-if-else-if-ladder-exercise-solution\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-91-if-else-if-ladder-exercise-solution\\\/\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-91-if-else-if-ladder-exercise-solution\\\/\",\"name\":\"Calculating Income Tax Using 'if-else-if' Ladder in C: Solution & Explanation\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-91-if-else-if-ladder-exercise-solution\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-91-if-else-if-ladder-exercise-solution\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/Figure-2-3.png\",\"datePublished\":\"2022-08-19T06:36:15+00:00\",\"dateModified\":\"2023-08-26T04:11:42+00:00\",\"description\":\"Income tax calculation using a 'if-else-if' ladder in C programming. The step-by-step solution, variable handling, and logical expressions.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-91-if-else-if-ladder-exercise-solution\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-91-if-else-if-ladder-exercise-solution\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-91-if-else-if-ladder-exercise-solution\\\/#primaryimage\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/Figure-2-3.png\",\"contentUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/Figure-2-3.png\",\"width\":1199,\"height\":491,\"caption\":\"Figure 2. Code\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-91-if-else-if-ladder-exercise-solution\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Microcontroller Embedded C Programming Lecture 91| &#8216;if-else-if&#8217; ladder exercise solution\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/\",\"name\":\"FastBit EBA\",\"description\":\"Your Online Academy of Embedded Systems\",\"publisher\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#organization\",\"name\":\"FastBit EBA\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/04\\\/logo-EzNrEnyr.png\",\"contentUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/04\\\/logo-EzNrEnyr.png\",\"width\":640,\"height\":640,\"caption\":\"FastBit EBA\"},\"image\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/fastbiteba\\\/\",\"https:\\\/\\\/x.com\\\/fastbiteba\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/fastbit-embedded-brain-academy-b3167b124\\\/\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCa1REBV9hyrzGp2mjJCagBg\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#\\\/schema\\\/person\\\/e32b38e733a0d76ffa7e6bc998652e5d\",\"name\":\"FastBitLab\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g\",\"caption\":\"FastBitLab\"},\"description\":\"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.\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Calculating Income Tax Using 'if-else-if' Ladder in C: Solution & Explanation","description":"Income tax calculation using a 'if-else-if' ladder in C programming. The step-by-step solution, variable handling, and logical expressions.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-91-if-else-if-ladder-exercise-solution\/","og_locale":"en_US","og_type":"article","og_title":"Calculating Income Tax Using 'if-else-if' Ladder in C: Solution & Explanation","og_description":"Income tax calculation using a 'if-else-if' ladder in C programming. The step-by-step solution, variable handling, and logical expressions.","og_url":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-91-if-else-if-ladder-exercise-solution\/","og_site_name":"FastBit EBA","article_publisher":"https:\/\/www.facebook.com\/fastbiteba\/","article_published_time":"2022-08-19T06:36:15+00:00","article_modified_time":"2023-08-26T04:11:42+00:00","og_image":[{"width":1199,"height":491,"url":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-2-3.png","type":"image\/png"}],"author":"FastBitLab","twitter_card":"summary_large_image","twitter_creator":"@fastbiteba","twitter_site":"@fastbiteba","twitter_misc":{"Written by":"FastBitLab","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-91-if-else-if-ladder-exercise-solution\/#article","isPartOf":{"@id":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-91-if-else-if-ladder-exercise-solution\/"},"author":{"name":"FastBitLab","@id":"https:\/\/fastbitlab.com\/blog\/#\/schema\/person\/e32b38e733a0d76ffa7e6bc998652e5d"},"headline":"Microcontroller Embedded C Programming Lecture 91| &#8216;if-else-if&#8217; ladder exercise solution","datePublished":"2022-08-19T06:36:15+00:00","dateModified":"2023-08-26T04:11:42+00:00","mainEntityOfPage":{"@id":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-91-if-else-if-ladder-exercise-solution\/"},"wordCount":1077,"commentCount":0,"publisher":{"@id":"https:\/\/fastbitlab.com\/blog\/#organization"},"image":{"@id":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-91-if-else-if-ladder-exercise-solution\/#primaryimage"},"thumbnailUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-2-3.png","keywords":["Microcontroller Embedded C programming Lectures"],"articleSection":["Blog"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-91-if-else-if-ladder-exercise-solution\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-91-if-else-if-ladder-exercise-solution\/","url":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-91-if-else-if-ladder-exercise-solution\/","name":"Calculating Income Tax Using 'if-else-if' Ladder in C: Solution & Explanation","isPartOf":{"@id":"https:\/\/fastbitlab.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-91-if-else-if-ladder-exercise-solution\/#primaryimage"},"image":{"@id":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-91-if-else-if-ladder-exercise-solution\/#primaryimage"},"thumbnailUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-2-3.png","datePublished":"2022-08-19T06:36:15+00:00","dateModified":"2023-08-26T04:11:42+00:00","description":"Income tax calculation using a 'if-else-if' ladder in C programming. The step-by-step solution, variable handling, and logical expressions.","breadcrumb":{"@id":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-91-if-else-if-ladder-exercise-solution\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-91-if-else-if-ladder-exercise-solution\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-91-if-else-if-ladder-exercise-solution\/#primaryimage","url":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-2-3.png","contentUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/08\/Figure-2-3.png","width":1199,"height":491,"caption":"Figure 2. Code"},{"@type":"BreadcrumbList","@id":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-91-if-else-if-ladder-exercise-solution\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/fastbitlab.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Microcontroller Embedded C Programming Lecture 91| &#8216;if-else-if&#8217; ladder exercise solution"}]},{"@type":"WebSite","@id":"https:\/\/fastbitlab.com\/blog\/#website","url":"https:\/\/fastbitlab.com\/blog\/","name":"FastBit EBA","description":"Your Online Academy of Embedded Systems","publisher":{"@id":"https:\/\/fastbitlab.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/fastbitlab.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/fastbitlab.com\/blog\/#organization","name":"FastBit EBA","url":"https:\/\/fastbitlab.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fastbitlab.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2026\/04\/logo-EzNrEnyr.png","contentUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2026\/04\/logo-EzNrEnyr.png","width":640,"height":640,"caption":"FastBit EBA"},"image":{"@id":"https:\/\/fastbitlab.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/fastbiteba\/","https:\/\/x.com\/fastbiteba","https:\/\/www.linkedin.com\/in\/fastbit-embedded-brain-academy-b3167b124\/","https:\/\/www.youtube.com\/channel\/UCa1REBV9hyrzGp2mjJCagBg"]},{"@type":"Person","@id":"https:\/\/fastbitlab.com\/blog\/#\/schema\/person\/e32b38e733a0d76ffa7e6bc998652e5d","name":"FastBitLab","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g","caption":"FastBitLab"},"description":"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."}]}},"_links":{"self":[{"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts\/10977","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/comments?post=10977"}],"version-history":[{"count":5,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts\/10977\/revisions"}],"predecessor-version":[{"id":11877,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts\/10977\/revisions\/11877"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/media\/10981"}],"wp:attachment":[{"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/media?parent=10977"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/categories?post=10977"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/tags?post=10977"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}