 Hello everyone. I am Sanjay Gupta. I welcome you on Sanjay Gupta Tech School. So this is day 7 of C and C++ coding bootcamp. And in this bootcamp we are learning basic building blocks of coding. So this bootcamp basically I started for BTEC students and non-technical folks who want to build their career in IT. So keeping that in mind, I am delivering all the things in detail and with the help of an example, right? So as you can see, today's topic is conditional statement and in today's session I will be talking about how we can implement logic with the help of simple if and if else. So in lots of programming languages like C++, Java, Apex, JavaScript everywhere we need to implement conditional statement. So in today's session, first I will discuss about the syntax like how we need to write these conditional statement and basis on that we will do some practice, right? So if I move forward, so I already explained you the topic and this is day 7, so keep yourself available to understand this and if you are not watching live, you are watching the recording then also whatever examples I will be explaining in this session. So just do practice at your own and I am sure like if you follow all the sessions of this bootcamp and you don't have any knowledge related to coding then you will be having that, right? So here you can see this is my profile. So if you are watching the videos for the first time on this channel so you should know about me, so if you go through this slide you will get to know about me, what I have done, what I am doing, right? And moving forward, consistency is the key. So this I revise in my every session like do regular practice if you want to learn something and if you want to join self-help group for the C and C++ bootcamp so you can scan this QR code. It is a telegram group where if you face any difficulty so we can discuss and follow Sanjay Gupta Tech School on YouTube, LinkedIn, Instagram and Telegram and all the important links to this bootcamp is available in the description, right? So let's start with the session so we will be discussing conditional statements today. Before starting this session I just want to show you the session tracker. So session tracker is like I am updating weekly basis and here you can see like if you are facing any difficulty in sessions which I am delivering in English. So I already have some prerecorded videos so you can take a look at these and you can come up in the live session if you want to ask questions. And we have completed total six sessions as of now. So basic features I already explained. Now we are moving to understand some difficult topics. So today I am starting with conditional statements and here also I provided some playlist which are having some prerecorded videos. So if you want to deep dive and if I miss any example of a live session, so you can just go through with this playlist and if you find something new, so you can just play that short video and you can understand the things, right? So keep an eye on the session tracker and those who are struggling understanding coding. So this bootcamp is very important for them. So pass this information to everybody, those who want to strengthen their coding skills. Okay, so let's understand the conditional statements. Basically in programming, in every programming language there are total four conditional statements are available. So we have simple if, we have if else, we have nested if and else if letter, right? So I just want to relate these conditional statements with our real life. So in real life what happens whenever you have something to do, so you always have some opinions about that like those who are like learning for a job. So they will be having something in mind in your mind like if I learn this, so I will I be getting the job. If I get the job, so what package I will be having. So you talk with yourself or maybe you talk with someone and you ask questions and there will be two options like you will be having something or you won't be having something. So whenever you have a condition, so it has two things with that condition. One is true and one is false. Like if you are learning this C and C++ programming language, so you might be thinking will I be able to understand Apex or not? So answer will be yes. So that is the condition. Whether you will be able to understand the Apex, this is the condition. It can be true or it can be false. So these are basically conditional statements which we have in real time as well. So I will tell you like how we can implement simple if with the help of syntax. I will tell you how we can write if else with the help of syntax. So today in this session I will be covering these two, simple if and if else. And in tomorrow's session I will be covering nested if and else if letter. So moving forward. So here you can see this is the way we write simple if. So basically simple if focuses on the true part only. So whenever you have a condition and if that condition is basically true, then only some set of instructions will be executed. Otherwise nothing will happen. So if your condition is false, so nothing will happen. So we have two type of syntaxes here in the first syntax. You can see we have if condition and then we have a statement. So here we have only one statement. So which is considered as true block. So if condition is true, then this statement will be executed. Then we have another form of the syntax like if condition. Here we have curly braces, right? So this is important to understand. So if you have more than one statements and you want to club them with a particular condition, so you need to enclose them inside curly braces, right? And if you enclose them as a curly inside curly braces, so it becomes a group of statement and if condition is true, so all those group of statement will be executed together, right? So now there are two notes that you need to remember. So if there is only one statement, then braces are optional. If I go back, so here you can see with this one statement, if you use curly braces or if you don't, then it is totally optional. But if you have more than one statement, then curly braces are important to use, okay? So if I go further, so this is the second point like else is optional in if statement, okay? So if you don't use else, else basically is used for false case. Else is basically used for false case. So if your condition is false, then we use else. So basically if I move to second syntax, so here you can see we have both the blocks. We have true block as well as false block. So if your condition is true, then true block statements will be executed and if your condition is false, then whatever you have written in else, so those set of instructions will be executed, right? So these are two syntaxes. Those are available. Now, first of all, I'm going to give you a little bit inside like how we can implement it. So I will be demoing both simple if and if else. And then we'll be implementing real life problems. So here I am writing if statement and I am writing five greater than two, okay? And here I'm writing printf and the statement is I am true block and after this, I am writing I will execute always. So here I am not using curly basis. Here I am not using curly basis. So can you tell me like what will be the output of this code, whether both the statements will be displayed or any one statement or what will happen? What will be the outcome of this code? So here condition is five greater than two and we have two printf statements. We don't have any curly basis. So you just need to write in the chat like both the statements will be printed or any one or nothing will be displayed. So now onwards this session will be interactive. So I will give you plenty of chances to respond in the chat so that I know whether you are having proper knowledge or not. So if you can answer in the chat so that I can confirm otherwise I will be running this code and we'll show you the result, okay? So as per me like five greater than two is true. So by default this first statement will be executed and the second statement will basically depend will not basically depend on this condition because we are not using curly basis. So what will happen if I click on run? So both the statement will be available as output. So you can see I am true blocked and I will execute always both the statements are displayed here, okay? So we have not used curly basis. Still both are executed now. If I change this condition five less than two. So in this case what will happen only the second statement will be executed because first is related to if but second statement second printf is not related to if. So this time like I'm using backslash and as well so that output will be available in new line. So I am running this code and here you can see the result. I will execute always. I am true block. This is not executed right? So here what you need to understand the importance of curly basis. Now if you thought if you have thought like those these two statements are related to this if condition. So this this is not true if you want to relate. So you need to open curly basis like this and now if you put it here. So this time both are together with this if so if this condition is true then both will execute. If this condition is false then nothing will be displayed on the output screen right and if condition is false nothing will happen. So if I execute the code so you will see no result. Nothing is shown. Okay because we don't have any else part. Now if I write else and if I use this statement. So here I am writing I am false block. So this way we have both true and false. So with if whatever you are writing is considered as true block and with else whatever you are writing is considered as false block. Okay. So this time whatever is the condition something will be coming up as the result. So if I click on run so here you will see I am false block and if I change the condition to true five greater than two. If I run it so you will see both the results. I am true block and I will execute always. So this way basically we write conditional statements to solve the problems. So today I will explain only two things like simple if and if else and generally we prefer if else. Okay. So these are the exercises that I am going to implement in today's session. Right. So these are like real time examples and if we implement these with the help of C programming so you will be learning the coding concepts properly. So the first problem says write a program to read a number and check whether it is even or odd and guys anytime those who are live and if you see any difficulty you want to ask any question. So feel free to write your question in the chat so that I can answer. And the question is like I already read it for you. So we need to check whether a number is even or odd. So first of all we need to understand like the difference between even or odd how we can identify. So we need to build the logic. So if we have a number and if that number is basically divisible by two if any number is basically divisible by two so that number will be considered as even and if that number is not divisible by two so that number will be considered as odd. So now we need to implement that solution. So I am going to implement it for you. So first of all I am creating a variable n. So here I took a data type int and a variable name is n. Now I am going to receive that input from user. So enter a number. So user will be entering a number and we are going to scan that number under a variable. So variable is n. So this way I am going to receive some input from user. Now I need to apply the logic. So basically my logic would be if now we will be using the operator. So if you remember in previous session I explained you about modulus and this double equals two. So double equals two basically compared two values. So here first this n modulus two will be evaluated. So can anyone tell me what is the use of this modulus operator? Can anyone tell me the use of this modulus operator? What will happen here like n modulus two? So what outcome will be getting here? So if you are able to answer so write your answer in the chat otherwise I will answer this question and will explain you like how it will be working. So Maima is answering reminder. So Maima it is remainder not reminder. So it will basically give you remainder value. So percent gives remainder value. Okay. So for example if n is having a value as five. So if you divide five by two. So remainder will be one. If you have ten inside n and if you divide that ten by two so remainder will be zero. Okay. So this way it will process. So if it is true like the result of n modulus two if it is zero and it is equals to zero. So here we'll be writing print f and in double quotes I can write number is even. And inside else I can write print f backslash n number is odd. Okay. So this way you just need to implement the solution. And here you can see I'm using curly basis with one statement. So use of curly basis with one statement is optional. If you want to use you can if you don't want to use you can avoid but best practice says use curly basis because it shows like from where your step began and from where it ended. So this way you can implement your solution. Okay. So this code will check whether the entered number is even or odd and we are having both true and false scenario. Now I'm going to run this code. So if I'm running so here you can see it is asking for number. So first of all I'm entering five. So it is showing number is odd. I'm going to run it again and this time I will be entering 10 and here you can see it is showing number is even. So in both the cases this code is working fine. So this way you just need to implement the logic and you need to decide like what should be in the true part and what should be in the false block of the conditional statement. Right. So if you have any question you can ask anytime and I'm moving to the next problem. So here the problem is we need to read age of a person and we need to check whether he or she is eligible for. Okay. So I just wrote it incorrectly. So it is for vote or not. So whether the person is eligible for vote or not. So like I live in India and in most of the country like eligibility for vote is 18 or above. So if you are 18 or above in respect to age. So you are eligible for vote. Right. So I'm going to modify this code now. So variable will be this like in N. Then here we need to write enter your age. Right. And I am going to read age in N. Now I need to modify this code. Okay. So this is very simple. So what you need to do? You need to write N greater than equals to 18. So here you can see I have used one more operator. So this time I'm using greater than equals to. I'm using one more operator that is greater than equals to. And here I'm going to show like the message. You are eligible to vote. Right. And if I copy this and I paste it here. You are not eligible to vote. So if the entered number is equal or greater than 18. Then this message will be displayed. Otherwise else part will be displayed. Okay. So this way you can see the code is implemented in front of you and how simple it is. We just need to decide this condition. And accordingly you can just draft the code. Now if I run this code. So I will be running it for both the cases positive and negative. So here I am entering the age. So if I enter 35. So you are eligible to vote. And if I run it again and let's say I'm entering 17. So it is showing you are not eligible to vote. So code is working fine in both the cases. So whenever you implement any code. So you need to test it in all respect whatever levels of conditions you have, you need to test it for all the conditions. So as a developer you need to work as a QA as well. QA is basically quality assurance analyst. So in IT industry we have two roles developer and QA. And if you are working as a developer. So in inbuilt you are a QA. But for proper testing we have a separate role that is QA. So QA basically test whatever code you have implemented whether it is working fine or not. Right. So this was second solution for the problem. Then we have one more problem which is like write a program to find out maximum from two numbers. So if we have two numbers and we need to find out maximum so that we can do with if else as well. Okay. So I'm going to implement this for you. So let's say we have and one and two. These are two numbers. So here I'm going to read values off. So I'm going to read two numbers and we are reading two numbers. So that's why we need to write %d two times. Then %n1 then %n2. So those two numbers will be available here. Now I'm going to write it from the beginning. So if n1 is greater than n2. So here I'm writing first number is max and I'm just copying it. Here I'm writing second number is max. Right. So if we compare both the numbers and one and two and if n1 is greater than greater than n2 so first number is max this will display otherwise else part will display. So this way one more solution I have implemented. So if you are a beginner so don't think these are very easy if you're a beginner. So you might be thinking like these are difficult to solve because after solution it becomes easy but if you see all these questions and you need to solve them yourself so it might look you difficult as well. So practice each and every code yourself and you can leverage online compiler and you can just do and implement the logic. And if you are BTEC student or if you are non tech guy so this is compulsion for you to practice all these things because this is the beginning of your coding journey and if you do proper practice so you will be able to understand the things and someone is asking about array so I just need to show the session tracker. So here you can see in week six we'll be discussing about array. So in session tracker everything is mentioned whatever we'll be learning and the link of the session tracker is available in the description of this video so you can find it there. Okay. So now what we need to do we need to find out maximum. Okay. So I'm just going to modify this. So we need to yeah we need to find out maximum among three numbers and that we need to do using logical operators. Okay. So we'll be having three numbers and those three numbers will be comparing and we need to identify which number is maximum. But here it is mentioned like we need to use logical operators. Okay. No worries. We can implement logical operators because I already showed you what logical operators are. So not at all problems. So here we need to have three variables and one and two and three. So we can read three numbers and one and two and three. Okay. So here we have and one and two and three three numbers are available. Now what we need to do we need to apply logical operators. So logical operator is and so if anyone is greater than and two and anyone is greater than and three. Right. So this is like anyone first number is max. Okay. So this way you can apply the condition. Right. Now here in else we can apply one more if so this is basically else if ladder that I will be explaining in detail tomorrow as well. But this is the problem where we need to use logical operator and without having multiple conditions we cannot use it. So here I am writing and two is greater than and one and and two is greater than and three. So second number is greater and then else here we can write third number is greater. Okay. So this way you can apply conditions. So this is basically logical operator logical and that we are using here. Right. And if any is greater than two and and one is greater than and three. So if and one is greater than with and two as well as and three then only first number is max same with and two if and two is greater than and one as well as and three. So second number is max if both not max then third number is max. So basically I wanted to show you how we can use logical and operator to join multiple conditions. So I hope with this example you are able to understand this. Yes. I come live daily this time only and if you want to know the sessions. So here this is available. So just have this. So I'm just sharing this for you. So I'm pasting it in the chat session tracker. So just have a look at it and weekly I am having three to four session and 9 30 PM IST is the time. So whatever topics I'm explaining is available here whatever I have delivered their links are available. So you can just follow this session tracker. So this is very like important for beginners that I'm preparing and I'm not seeing the number like how many students are live. I'm targeting the future audience because I know one day this will go viral and people like those who are from college and from non-technical background they will be learning these as recorded videos. So I'm preparing for this those and those who are joining live they have a chance to interact with me if you are facing any difficulty in understanding logic so you can discuss. So I hope this way you are understood like how we can implement complex problems and it is very easy. Okay. And with this else if we need to provide one space as well. So by seeing this code it becomes very easy but when you try to implement it might be having some errors. So what you can do just see on this slide don't see the solution until you implement once you implement you can just go forward this video and you can just verify how I implemented and if both are correct and then I think you are learning and that is great and that is the objective of this bootcamp. So now I'm going to explain the next thing which is last program of this session. So we need to read basic salary of an employee and we need to print gross salary. So here we have a condition like if basic salary is greater than equals to 10,000 so we need to calculate separate DA and HRA like 40% and 20% otherwise like if it is less than 10,000 so we need to calculate separate DA and HRA. So here again there is a mistake so let me correct it out so it is not DA sorry it is not DS it is DA. So here you can see basic salary like we need to calculate 40% 20% one combination and we need to calculate 20% 10% this is another combination. So if basic salary is greater than equals to 10,000 so we have separate group and if it is less than 10,000 we have separate group and after that we need to calculate gross salary. So gross salary is basically total of basic salary plus DA plus HRA. So this I hope you know because this problem I already explained without conditional statement now we need to solve this with the help of conditional statement. So now we need different variables so I am just implementing it from the beginning. So I am taking data type as float for different programming languages it is differently available so in C programming it is float because we will be having decimal point as well. So basic salary DA, HRA and gross salary then I am writing printf here I am writing enter basic salary. So we just need to read basic salary because DA, HRA and gross salary we will be calculating. So this way we are able to receive basic salary from the user right now I am going to write the condition. So condition is if basic salary greater than equals to 10,000. Okay so we have some set of conditions if it is greater than equals to 10,000 so DA is 40% and HRA is 20% of basic salary. So let's calculate it. So what we need to write DA equals to basic salary into 40 so let me have it in the parenthesis and divide it by 100. So this way 40% of basic salary is calculated as DA then we have HRA so it is basic salary into 20% right. So here you can see 20% of basic salary. So 40% of HRA and 40% of sorry DA is 40% and HRA is 20% so that we need to calculate here so it is 20% so this is done. Now we need to implement else part so if basic salary is less than 10,000 so this condition will be false because it is for greater than equals to 10,000. Now what we need to do just copy and paste it. So if you copy paste you just need to modify these figures and here you can see DA is 20 and HRA is 10% if condition is false. So here you can quickly modify it to 20 you can modify it to 10 so this way this part is implemented. Now no matter whatever true or false block executes we will be having data in DA and HRA variables because either your basic salary is greater than equals to 10,000 or it is less than 10,000. Now what we need to calculate we need to calculate gross salary. So gross salary equals to basic salary plus DA plus HRA. So this is the formula and with this formula we will be having gross salary. So if you want to display gross salary you can write the conditions this way. So this is the printf. So this way I am able to implement the complete solution in front of you and if I run it so it will ask basic salary let's say I am entering 1000 so that we can calculate the results quickly. So if it is 1000 so 20% of 1000 is 200 and 10% of 1000 is 100 so total is 1300 which is the gross salary. And if I enter 10,000 so it will be true so accordingly conditions will be executed so right now I am going to enter 10,000 so for 10,000 you can see basic salary like DA is 40 and HRA is 20% so 40% of 10,000 is 4,000 20% of 10,000 is 2,000 so 6,000 will be added so it will be 16,000 and which is the gross salary. So this way our code is working fine. So someone is asking GS why I wrote it outside because if I write it inside so I need to write it inside if and inside else so it will be available twice. Here and here and it is common if I cut it from here so I need to write it twice so this is best practice this is not a best practice because you are repeating you are increasing number of lines in the code so what you need to do you just need to remove it and you need to write it outside because it is a common statement no matter whether true block executes or false block executes you just need to run this code so that's why it is outside if and else so this is nice question I appreciate it and I hope I am able to answer and you are able to understand okay so if you have any more questions you can ask so I hope I am able to explain the things to you and you can just practice these questions at your own and if you are a beginner so for you these codes are very important to understand and this sheet will be important for you and here you can see more programs on FL so if you click on this link so there will be a playlist so if you open it so you will have lots of videos here right so this is a playlist which is having some videos so some different problems you will find and you can just practice and same for this more programs on basic problems so for college going students if you are starting your BTEC journey so for you this sheet will be very much important so those who are watching this recording or you are watching this live and if you know someone who is about to start their BTEC journey or already started their BTEC journey and they want to learn CNC++ totally free of cost and with proper sessions proper examples so I think this bootcamp sheet will help them and once they complete CNC++ they can immediately jump on learning Salesforce admin and everything is available in the same sheet so here you can see in the same sheet admin and development related stuff is available and whatever bootcamp I will be having in future so everything will be available in the same sheet share this information with lots of folks those are in your circle so that they can also be benefited so I have one more question even if I enter alphabets instead of numeric also it is giving output yes so that you need to check so that is bad data if you are entering some alphabets still it is giving you result because in that case it will become false so execute this else part so you just need to check it whether it is number, alphabets so in C programming there are less features available but like if you talk about apics and if you are working in lightning web component and if you are receiving these kind of data so we can check that before process so that is data related issue so will this course will be beneficial for placement yes this course will be beneficial for placement for college students if you are like non-technical folks you are already passed out or you are having some career gaps so you need to have additional skill set so this CNC++ bootcamp is for beginners to understand the coding related stuff and then you can jump to this Salesforce stuff and you can learn this and I think these will be very less sessions so in seven sessions we have covered lots of things and if you see like for C programming we have 38 and in total we have 63 and I am sure this will be reduced so it will be around 50 to 60 so 50 to 60 sessions if you give so you will be learning two different programming languages okay so I hope this is it and you are able to understand things and will connect tomorrow again with some more problems and will be explaining you about nested if and else if later so first we will be understanding the syntax then I will be explaining you lots of program so will give you all the demo will be implementing so that you can understand and later you can implement that at your own okay guys so this is it for today thank you for joining the session if you are watching the recording thank you for watching please share this recording or channel with everybody those who are willing to jump to IT and want to learn different programming languages and different other job oriented courses so soon there will be lots of course coming up so please share the information thank you so much bye see you tomorrow