 Hello, hi everyone. I'm Sanjay Gupta. I welcome you on Sanjay Gupta Tech School. So this is day eight of C and C++ coding bootcamp. And today the topic which we are going to discuss is conditional statement that we discussed yesterday as well. But today I will guide you how you can implement programs using nestediff and alceflatter. So yesterday we saw like if you have only one condition, so how you can implement true and false part. But today you will see like if there are more than one conditions available. So how we can implement them with the help of nestediff and alceflatter. So that I'm going to explain you today. And I want to share one thing like this bootcamp is dedicated for BTEC students, those who are starting their programming journey. And for non-technical folks who want to switch to ID, so if they want to brush up their coding skills. So this bootcamp will be very much fruitful for them. So moving forward, if you have joined or if you are for the first time on this channel and if you want to know about me. So this slide will tell you about me like I'm running Sanjay Gupta Tech School Award for 16 years, more than 16 years. And helping people like students, freshers and professionals to build their career in Salesforce and IT ecosystem. Right. So with this note moving ahead, be consistent, do regular practice. So no matter how many students are joining live or how many are watching recording. So I'm consistent. I will be delivering everything. So whatever I started, I will finish that as well. And if you want to join Telegram group, so you can scan this QR code. Just follow Sanjay Gupta Tech School on YouTube, LinkedIn, Instagram and Telegram. And all the important video links are available in the description. Right. So moving ahead, let's discuss about conditional statements. So yesterday I told you we have four types of conditional statements. Simple if, if else, nested if and else if ladder. So first two I already discussed with you yesterday. Now today we'll be focusing on the next two. Right. So we'll understand the use of nested if and else if ladder. So I will be implementing some examples. So if we do a recap. So yesterday I told you like we have simple if where else is optional. And if you have one statement, then curly braces are optional. And if you have group, then curly braces are compulsion. Now if we move forward. So here you can see we have these notes which I already explained. Then this is if else here we have true as well as false block. So whenever you have else, so it will give you the false block. Then I explained you these examples yesterday. So we implemented all the solutions. So I hope if you are a beginner, so you have also practiced it. So just use online compiler and implement all these codes yourself so that you, you can have enough confidence like you are able to implement simple, simple problems. Okay. Moving forward. Next we have this statement. So I'm just checking to have a pencil. Okay. No. So basically here what is happening if you focus on this syntax. So this syntax is having multiple if condition. So here if this first if condition is true, basically the first if condition is true. So next if condition will be evaluated. So basically this if condition starts from here and here right till here. This is the true block right inside this true block. We have one more if else block. So that's why it is known as nested if. So if you are using one if inside another if. So this is basically known as nested if. Okay. So if first condition is true, then second condition will be checked. If second condition is also true, then this statement will be executed. Right. If second condition is false, then this else block will be executed. Okay. And if first condition that is available on top. If this first condition is false, then this last else part will be evaluated. Okay. So this way we have multiple if conditions here. So I will be implementing solution with the help of nested if. So I will try to implement the same problem with the help of nested if and with else if letter. So we have one more syntax that is else if letter. So first we need to understand the syntax and then we'll be implementing the solution. So if you see this, so what is happening here? We have if condition, then we have a statement. So this is the true part and if this condition is false, like if you are having else part and inside else, we have one more if else combination. So if your first condition is false, then only your next if else block will be evaluated. Okay. So if we compare both the syntax, if I go back, so what is happening in nested if, if the first condition is true, then we have one more condition in as if letter. What is happening? If your first condition is false, then you are having one more if else block. And all these syntax, all these conditional statements, we'll be using in C programming C plus plus apex Java. So in all the programming languages, mostly we implement conditional statements in the same way. Right. So I gave you proper insight. Now I'm going to implement a problem in front of you so that you can have a proper insight like how we can solve a problem. So I will be solving the last one first, read a number and check whether it is positive, negative or zero. And I will try to implement it both the ways. First, I will be implementing it with the help of nested if and then I will implement the solution with the help of else if letter so that you will be having enough insight. Okay. So here we have this main function. So here I'm creating a variable into num. So whatever value I will be reading so that will be stored inside the num variable. Right. Now, first of all, we need to receive that value from the user. So enter a number. So without entering a number, we cannot do any calculation. So that number will be stored inside this num variable. Now, after this, what we need to do, we just need to apply conditional statements. Right. So here we have a requirement like we need to check whether number is positive, negative or zero. We have three situations. Okay. So first of all, I am applying if condition. So here I am writing num is greater than equals to zero and we have a block. Right. Then we'll be having else block. So we have true as well as false block. Okay. But in true block, we have two things. Either number will be greater than zero or number will be equals to zero. Right. We have two situations. Now, if this block is true, like number is equals to zero or greater than zero. So we need to identify whether it is greater than zero or equals to zero. So here inside this, if I will be writing one more if where I will be checking this. So if it is equals to zero, so I will write. Number is zero. And here I can write else where I can write print of number is positive. So this is, this is a true block. This whole is the true block for this if condition inside this if condition. We have one more if else block, but it is part of this condition. So if this is true, then only these if else will be evaluated otherwise not. Now, if user enters a number as negative, if user enter a negative number. So tell me line number nine will be true or false. So your answer should be false because number is negative. So this condition will become false. So here in else part what we can do. We can write print of and we can simply write number is negative. Okay. So this way in front of you, I saw the complete implementation. So here you can see the program on the whole program on a single page. So this way I implemented this solution with the help of nested if. So this approach is nested if here I am using one if inside another if in the true part. So this approach will be known as nested if. Okay. Thank you for appreciating my efforts and fire gaming. Good evening. So I hope everybody those who are online watching live this session. You understood this and if you're watching this recording. So I hope you are able to understand whatever I demonstrated. Now the same problem I'm going to implement using else if letter. So the same problem I'm going to implement with else if letter. Okay. So I'm just removing this code from here so that I can start implementing it from the beginning and you can understand. So first of all, I will be checking number is greater than zero. So one condition at a time if it is true, I can simply write number is positive. Right. If this is false, so here you can write else if num is less than zero. If it is true, so you can write number is negative. And if it is also false, then you can use else. You can write printf number is zero. So this way you can implement else if letter. So this is first of condition. If it is if it is true, so this printf will work. If it is false, so else if will be evaluated, then this printf will be working. Then again, we have else. So this printf will be working and result will be displayed. Okay. So this way you can use else if letter to solve the problem. So I gave you both the examples and I hope you understood. So let's execute this and the previous one I forgot to implement run. So if you implement and execute, so it will give you correct results. So I will execute it three times. So first time entering five, it is giving positive. I'm running it again. And this time I'm entering negative value. So it is giving me negative and third time I will be entering zero. So it will give me zero. So this way the code is working fine in all the cases. Right. So I hope with this way you are able to understand how else if sorry how nested if and else if letter are working. Okay. Now write a program to find out maximum from three numbers. So I'm going to solve it for you. So we'll be having and one and two and three. So these are three variables. So here I'm writing and three numbers. So we need to receive three numbers from users. So three times porcent d and one then ampersand and two then ampersand and three. Okay. Now I need to implement the solution. So if anyone is greater than and two. So here I will be writing and one is greater than and three. Right. If anyone is greater than and two and one is greater than and three. So here I can write printf. Number one is max. Now we need to write else part for this if okay. So this is if else pair. So if this condition is false like and one is not greater than and three but and one is greater than and two. Right. So and one is greater than and two but and one is not greater than and three. So automatically number three will be maximum here. So here we can write num three is max. Now it may possible like your first condition is false. So here what you will do you will write else if and two is greater than and three. Okay. And here you will be writing printf number two is max. So what will happen if this condition is false if the first condition is false. So and two is greater. So control will come automatically to this else part. Here in this else we are having if so if and two is greater than and three. So number two will be max and otherwise what we can write else number three is max. So this way we can implement the code. Now if I run this code so I just need to provide. Okay. There is a error at line number 21. Okay. Now this code will run properly. There were some extra curly braces. So here you can see I entered three numbers three four five. So number three is max. So this way you can implement. So this is the this is the combination of nested if and else if letter actually. Okay. So I hope with this way you are able to understand the concepts. Now we have one more problem that says we need to read cost price and selling price of an item and we need to figure out whether Sailor is making profit or loss. Right. So we need to read two things cost price and selling price. Okay. So we just need to identify profit and loss. So here I am going to create float variables. So cost price and selling price. Okay. So here I need to read these values. So enter cost price and selling price. Right. So this way cost price and selling price will be received from the user with the help of this print f and scan f. So all the values will be available. Now we have three situations. There can be chances of profit if sailing price is greater than cost price. So this is one situation. Second is if cost price is high and selling price is low. So Sailor will make loss. And third can be like if both are equal. If sailing price and cost price both are equal. In that case, there will be no profit nor loss. Right. So there are three situations. Now I'm going to implement it. So we can implement it using nested as well as using else if ladder. So I am preferring else if ladder because that is easy to implement. So if cost price is okay. Let's do profit first and we will show like how much profit or how much loss is there. So if sailing price is greater than cost price. So I can write print if profit equals to person D and here I can write SP minus CP. So I'm subtracting both sailing price and cost price. If it is false. So I need to write else if CP greater than SP. Like if your cost price is greater than sailing price, it means there is loss. So here I need to write loss and it will be cost price minus sailing price. And if it is also false. So here I can write no loss, no profit. So this way this code is implemented. So there are total three scenarios. First one is for profit. Second one is for loss. Third one is for no loss, no profit. So here I am implementing it with the help of else if ladder. So this is if condition which is showing true value then else if which is like false. It is also having else part. So accordingly wherever condition is true that particular block will be executed. Okay. If I run this code. So there is a mistake. I use float. So here I need to use percent F. So I'm using percent F. Now I think it will run properly. Okay. So it is asking for cost price and sailing price. So let's say cost price is 1000. Sailing price is 1500. So here you can see profit equals to 500. So this way this code will be working. So whenever you get a chance implement this solution in your system and you can try and all these problems you can implement at your own without seeing the solutions so that you can have enough confidence like you are able to understand the things. So next is read marks of three subjects and display total marks, percentage and division. Right. So I'm going to implement this as well. Okay. So here I'm using integer M1 M2 M3 total percentage. Right. Then I will be receiving marks of three subjects. So enter marks of three subjects. Then scan F percent D percent E percent E three times. Then first marks will go to M1. Second marks will go to M3. Sorry. M2. Then third will go to M3. Now first we need to calculate total. So for total we will be adding all these three values. Now we need to calculate percentage. So I'm assuming each subject maximum marks is 100. So total upon 300 into 100. And for safe side I'm enclosing them in parenthesis. So this way result will be calculated. And I think let's take it as float because percentage will be in float. So and marks can also have values and decimal point. So I'm taking it as float. So this way now I'm going to display total and percentage. Right. So this way total marks will be displayed. Then we need to use print F total percentage. Right. Now we need to apply conditional statements so that we can identify division. So for division what I need to do like I just need to use percentage. So if it is greater than equals to 60. So here I can write first division. Then else if greater than equals to 48. So I'm writing second division and in calculation of this division if I'm wrong. So correct me. So you can paste your calculation in the chat like this is the range for division. So I'm writing it as per my knowledge and I think these are correct. Still if you find something incorrect. So you can just let me know. And last one is for print F fail. So first division greater than equals to 60. Second is greater than equals to 48. Third is greater than equals to 36 and last one is fail. So this way all these conditions I have provided. Okay. Now what will happen? First of all we need to provide three subject marks then total percentage will be calculated. Total percentage will display on the UI and then this calculation will happen as per your percentage. This calculation will print some value on output as result. Right. So I'm going to execute this code so that we can identify the result. So I'm entering marks like 80 90 and 70. So here you can see total is 240 percentages 80 and it is showing first division. So if Marx is 60 and greater than 60 so automatically it will execute print F and rest of the else if won't be checked. If it is less than 60 then only it will come here and we'll check whichever is true. Right. So if anyone condition is true so rest of the conditions won't be checked. So that's why use of this else if ladder is useful. Right. So I hope with this note you are able to understand all these problems which I explained to you. So this way like I tried to explain you all the conditional statements that we use in the programming and whenever you will be learning apex programming. So you will see all these conditional statements there. So now after watching these videos live and practicing I hope there you won't be having any problem. And if you are a BTEC student so these are very good questions which which which which will come in your theoretical exam and your practical laboratory laboratory. So do practice all the questions and I have a session tracker as well. So here you will find some more things. Right. So whatever supporting material I have. I am providing those here as well and you can go through this exercise sheet. So I'm documenting all the exercises here so that collectively they will be available here. So this exercise sheet will be very much beneficial for all the BTEC students. Okay. With this note I end my session here only if you have any question you can ask. So like next in next session we will be understanding one more statement that is known as switch statement. So that is also useful. So I will be explaining you that. Okay. So if there is no question so I take your leave. Thank you so much for watching this session. See you in the next session. Thank you so much and do regular practice. Thank you everybody for joining this session live and thank you those who are watching the recording. See you in the next session. Thank you. Bye.