Difference between revisions of "C-and-C++/C2/If-And-Else-If-statement/English-timed"
From Script | Spoken-Tutorial
PoojaMoolya (Talk | contribs) |
PoojaMoolya (Talk | contribs) |
||
(6 intermediate revisions by 2 users not shown) | |||
Line 5: | Line 5: | ||
|- | |- | ||
| 00:02 | | 00:02 | ||
− | | Welcome to the spoken tutorial on '''Conditional statements in C and C++''' | + | | Welcome to the spoken tutorial on '''Conditional statements in C and C++'''. |
|- | |- | ||
| 00:08 | | 00:08 | ||
− | | In this tutorial we will learn | + | | In this tutorial we will learn: |
− | + | ||
|- | |- | ||
| 00:11 | | 00:11 | ||
− | | | + | | How to execute a single '''statement''' |
− | + | ||
|- | |- | ||
| 00:14 | | 00:14 | ||
| How to execute group of '''statements'''. | | How to execute group of '''statements'''. | ||
− | |||
|- | |- | ||
| 00:16 | | 00:16 | ||
| We will do this through examples. | | We will do this through examples. | ||
− | |||
|- | |- | ||
Line 33: | Line 29: | ||
|- | |- | ||
| 00:25 | | 00:25 | ||
− | | To record this tutorial, I am using | + | | To record this tutorial, I am using '''Ubuntu Operating system''' version 11.10. |
− | + | ||
|- | |- | ||
| 00:31 | | 00:31 | ||
− | | '''gcc''' and '''g++ Compiler''' version 4.6.1 | + | | '''gcc''' and '''g++ Compiler''' version 4.6.1. |
|- | |- | ||
| 00:38 | | 00:38 | ||
− | | Let us start with the | + | | Let us start with the introduction to conditional '''statements'''. |
− | + | ||
|- | |- | ||
| 00:43 | | 00:43 | ||
| A '''statement''' in a program controls the flow of program execution. | | A '''statement''' in a program controls the flow of program execution. | ||
− | |||
|- | |- | ||
| 00:49 | | 00:49 | ||
− | | It helps to make decision on | + | | It helps to make decision on what code is to be executed. |
− | + | ||
|- | |- | ||
| 00:55 | | 00:55 | ||
|We can check the conditions, whether true or false. | |We can check the conditions, whether true or false. | ||
− | |||
|- | |- | ||
Line 66: | Line 57: | ||
|- | |- | ||
| 01:07 | | 01:07 | ||
− | | | + | | Let us understand the flow of '''if''' statements. |
− | + | ||
|- | |- | ||
| 01:13 | | 01:13 | ||
− | | Here, if the condition is true then | + | | Here, if the condition is true then '''statement 1''' will be executed. |
− | + | ||
|- | |- | ||
| 01:20 | | 01:20 | ||
− | | If the condition is false then ''' | + | | If the condition is false then '''statement 2''' will be executed. |
|- | |- | ||
| 01:29 | | 01:29 | ||
− | | | + | | Now we will see the flow of '''else if''' statement. |
− | + | ||
|- | |- | ||
| 01:32 | | 01:32 | ||
− | | Here, if ''' | + | | Here, if '''condition 1''' is true then '''statement 1''' will be executed. |
− | + | ||
|- | |- | ||
| 01:41 | | 01:41 | ||
− | | If ''' | + | | If '''condition 1''' is false then it will check for another condition that is '''condition 2'''. |
− | + | ||
|- | |- | ||
| 01:49 | | 01:49 | ||
− | | If ''' | + | | If '''condition 2''' is true then '''statement 3''' will be executed. |
− | + | ||
|- | |- | ||
| 01:54 | | 01:54 | ||
− | | And If ''' | + | | And If '''condition 2''' is false then '''statement 2''' will be executed. |
|- | |- | ||
| 02:02 | | 02:02 | ||
| Now Let us move on to our program. | | Now Let us move on to our program. | ||
− | |||
|- | |- | ||
| 02:06 | | 02:06 | ||
| I have already typed the code on the editor. | | I have already typed the code on the editor. | ||
− | |||
|- | |- | ||
| 02:09 | | 02:09 | ||
− | | So let me open it. | + | | So, let me open it. |
− | + | ||
|- | |- | ||
| 02:13 | | 02:13 | ||
− | | Note that our | + | | Note that our file name is '''ifstmt.c'''. |
|- | |- | ||
Line 128: | Line 110: | ||
| 02:26 | | 02:26 | ||
| Let me explain the code now. | | Let me explain the code now. | ||
− | |||
|- | |- | ||
Line 136: | Line 117: | ||
|- | |- | ||
| 02:34 | | 02:34 | ||
− | | This is our '''main | + | | This is our '''main()''' function. |
|- | |- | ||
| 02:38 | | 02:38 | ||
− | | Here we have declared three | + | | Here we have declared three '''integer variables''' '''a, b''' and '''sum.''' |
|- | |- | ||
| 02:46 | | 02:46 | ||
− | | | + | | Here we are asking for user input. |
− | + | ||
|- | |- | ||
| 02:49 | | 02:49 | ||
| User will enter the values of a and b. | | User will enter the values of a and b. | ||
− | |||
|- | |- | ||
Line 159: | Line 138: | ||
| 02:58 | | 02:58 | ||
|The '''scanf()''' function reads data from the console. | |The '''scanf()''' function reads data from the console. | ||
− | |||
|- | |- | ||
| 03:02 | | 03:02 | ||
| It then stores the result in the given '''variable.''' | | It then stores the result in the given '''variable.''' | ||
− | |||
|- | |- | ||
| 03:06 | | 03:06 | ||
− | | The''' format specifier '''in the''' scanf() '''helps to know the type of data. | + | | The '''format specifier''' in the '''scanf()''' helps to know the type of data. |
− | + | ||
|- | |- | ||
| 03:10 | | 03:10 | ||
− | | Like here we have %d it denotes that we are dealing with integer data type. | + | | Like here we have '''%d''', it denotes that we are dealing with integer data type. |
|- | |- | ||
| 03:18 | | 03:18 | ||
− | | Here we add the values of''' a''' and '''b.''' | + | | Here we add the values of '''a''' and '''b.''' |
− | + | ||
|- | |- | ||
Line 190: | Line 165: | ||
|- | |- | ||
| 03:29 | | 03:29 | ||
− | | This is our '''if | + | | This is our '''if''' statement. |
|- | |- | ||
Line 202: | Line 177: | ||
|- | |- | ||
| 03:42 | | 03:42 | ||
− | | Now let me comment out | + | | Now let me comment out these lines. |
|- | |- | ||
|03:48 | |03:48 | ||
− | |This is our return statement. | + | |This is our '''return''' statement. |
|- | |- | ||
| 03:51 | | 03:51 | ||
− | | | + | | Now click on '''Save'''. |
|- | |- | ||
| 03:53 | | 03:53 | ||
− | |First we will see the execution of if statement. | + | |First we will see the execution of '''if''' statement. |
|- | |- | ||
| 03:58 | | 03:58 | ||
− | | | + | | Please open the terminal window by pressing '''Ctrl, Alt''' and '''T''' keys simultaneously on your keyboard. |
|- | |- | ||
|04:09 | |04:09 | ||
− | | | + | | To compile, type '''gcc space ifstmt dot c space -o space if''' and press Enter. |
|- | |- | ||
| 04:20 | | 04:20 | ||
− | | | + | | To execute, type '''./if''' (dot slash if). Press Enter. |
|- | |- | ||
| 04:26 | | 04:26 | ||
− | | | + | | It is displayed as '''Enter the values of a and b'''. |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
|- | |- | ||
Line 242: | Line 213: | ||
|- | |- | ||
| 04:38 | | 04:38 | ||
− | |The output is displayed as Sum of a and b is 22. | + | |The output is displayed as '''Sum of a and b is 22. Sum is greater than 20'''. |
|- | |- | ||
Line 250: | Line 221: | ||
|- | |- | ||
| 04:48 | | 04:48 | ||
− | | | + | | We will check another condition. |
|- | |- | ||
Line 262: | Line 233: | ||
|- | |- | ||
| 05:00 | | 05:00 | ||
− | |Now click on '''Save.''' | + | |Now click on '''Save.''' This is our '''else-if''' statement. |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
|- | |- | ||
| 05:05 | | 05:05 | ||
− | |Here, we check another condition whether | + | |Here, we check another condition whether '''Sum''' is greater than 10. |
|- | |- | ||
| 05:11 | | 05:11 | ||
− | |If the condition is true then we print | + | |If the condition is true then we print 'Sum is greater than 10 and less than 20'. |
|- | |- | ||
Line 289: | Line 256: | ||
|- | |- | ||
| 05:26 | | 05:26 | ||
− | | It is displayed as | + | | It is displayed as |
|- | |- | ||
| 05:28 | | 05:28 | ||
− | |Enter the value of a and b. | + | |'''Enter the value of a and b'''. |
|- | |- | ||
| 05:30 | | 05:30 | ||
Line 300: | Line 267: | ||
|- | |- | ||
| 05:35 | | 05:35 | ||
− | |The output is displayed as: Sum of a and b is 12. | + | |The output is displayed as: '''Sum of a and b is 12'''. |
|- | |- | ||
| 05:38 | | 05:38 | ||
− | |Sum is greater than 10 and less than 20. | + | |'''Sum is greater than 10 and less than 20'''. |
|- | |- | ||
| 05:42 | | 05:42 | ||
|Let me clear the prompt. | |Let me clear the prompt. | ||
− | |||
|- | |- | ||
Line 317: | Line 283: | ||
|- | |- | ||
| 05:48 | | 05:48 | ||
− | | I will remove the comment from here and here. Now click on | + | | I will remove the comment from here and here. Now click on Save. |
|- | |- | ||
| 05:56 | | 05:56 | ||
− | | | + | | If both the above conditions are false then we print 'Sum is less than 10'. |
|- | |- | ||
| 06:04 | | 06:04 | ||
− | |This is our else statement. | + | |This is our '''else''' statement. |
|- | |- | ||
| 06:07 | | 06:07 | ||
− | | Now let us execute and see. | + | | Now let us execute and see. Come back to our terminal. |
|- | |- | ||
Line 337: | Line 303: | ||
|- | |- | ||
| 06:18 | | 06:18 | ||
− | | Here it is displayed as | + | | Here it is displayed as '''Enter the value of a and b'''. |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
|- | |- | ||
Line 349: | Line 311: | ||
|- | |- | ||
| 06:27 | | 06:27 | ||
− | | | + | | The output is displayed as '''sum of a and b is 8'''. |
|- | |- | ||
| 06:31 | | 06:31 | ||
− | |Sum is less than 10. | + | |'''Sum is less than 10'''. |
|- | |- | ||
Line 365: | Line 327: | ||
|- | |- | ||
| 06:41 | | 06:41 | ||
− | | Suppose, here at the end of if statement I will type a semicolon. | + | | Suppose, here at the end of '''if''' statement I will type a semicolon (;). |
|- | |- | ||
| 06:47 | | 06:47 | ||
− | |Let see what will happen. Click on '''Save.''' | + | |Let us see what will happen. Click on '''Save.''' |
− | + | ||
− | + | ||
|- | |- | ||
Line 383: | Line 343: | ||
|- | |- | ||
| 06:56 | | 06:56 | ||
− | | We see an error: else without a previous if | + | | We see an error: ''' 'else' without a previous 'if' ''' |
|- | |- | ||
| 07:02 | | 07:02 | ||
− | | Come back to our program.It is | + | | Come back to our program. It is a syntax error. |
|- | |- | ||
| 07:07 | | 07:07 | ||
− | | | + | |'''if''' statement will never terminate with a semicolon. |
|- | |- | ||
| 07:10 | | 07:10 | ||
− | |And the else if statement will never work without an if. | + | |And the '''else if''' statement will never work without an '''if'''. |
|- | |- | ||
| 07:16 | | 07:16 | ||
− | | Let us fix the error. Delete the semicolon ; here | + | | Let us fix the error. Delete the semicolon (;) here. |
|- | |- | ||
Line 415: | Line 375: | ||
|- | |- | ||
| 07:35 | | 07:35 | ||
− | |Enter the value of a and b | + | |Enter the value of a and b. |
|- | |- | ||
Line 427: | Line 387: | ||
|- | |- | ||
| 07:45 | | 07:45 | ||
− | |Sum of a and b is 9. Sum is less than 10. | + | |'''Sum of a and b is 9. Sum is less than 10'''. |
|- | |- | ||
Line 439: | Line 399: | ||
|- | |- | ||
| 07:59 | | 07:59 | ||
− | | | + | | I will change a few things here. |
|- | |- | ||
| 08:03 | | 08:03 | ||
− | | Press '''Shift, Ctrl and S''' keys simultaneously on your keyboard. | + | | Press '''Shift, Ctrl''' and '''S''' keys simultaneously on your keyboard. |
|- | |- | ||
| 08:11 | | 08:11 | ||
− | |Now save the file with an extension ''' dot cpp''' and | + | |Now save the file with an extension '''dot cpp''' and click on ''' Save'''. |
|- | |- | ||
| 08:20 | | 08:20 | ||
− | | | + | | We will change the header file as '''iostream'''. |
|- | |- | ||
Line 459: | Line 419: | ||
|- | |- | ||
| 08:30 | | 08:30 | ||
− | | Now click on the | + | | Now click on the Search for and replace text option. |
|- | |- | ||
| 08:35 | | 08:35 | ||
− | |Let us replace the '''printf '''statement with the '''cout | + | |Let us replace the '''printf '''statement with the '''cout''' statement. |
|- | |- | ||
| 08:40 | | 08:40 | ||
− | |Click on '''Replace all''' and click on | + | |Click on '''Replace all''' and click on Close. |
− | + | ||
− | + | ||
|- | |- | ||
| 08:46 | | 08:46 | ||
− | | Now delete the | + | | Now delete the closing brackets here. |
|- | |- | ||
| 08:49 | | 08:49 | ||
− | |Replace the '''scanf''' statement with the '''cin''' statement. | + | |Replace the '''scanf()''' statement with the '''cin''' statement. |
|- | |- | ||
| 08:54 | | 08:54 | ||
− | |Type '''cin and two closing angle brackets >>''' | + | |Type '''cin''' and '''two closing angle brackets >>'''. |
|- | |- | ||
| 09:00 | | 09:00 | ||
− | |As we use '''cin >> | + | |As we use '''cin >>''' function to read a line in C++. |
− | + | ||
|- | |- | ||
Line 493: | Line 450: | ||
|- | |- | ||
| 09:09 | | 09:09 | ||
− | |Delete the '''comma''' and '''ampersand | + | |Delete the '''comma''' and '''ampersand &'''. |
|- | |- | ||
Line 501: | Line 458: | ||
|- | |- | ||
| 09:17 | | 09:17 | ||
− | |Again delete the '''ampersand'''and the closing brackets. Now | + | |Again delete the '''ampersand'''and the closing brackets. Now click on '''Save'''. |
|- | |- | ||
Line 509: | Line 466: | ||
|- | |- | ||
| 09:31 | | 09:31 | ||
− | |Now delete the | + | |Now delete the '''backslash n (\n)''' and '''format specifier'''. |
− | + | ||
|- | |- | ||
| 09:37 | | 09:37 | ||
− | | Now | + | | Now type two opening brackets. |
|- | |- | ||
| 09:42 | | 09:42 | ||
− | |Again type two opening angle brackets and''' | + | |Again type two opening angle brackets and '''within the double quotes type backslash n “\n”.''' |
|- | |- | ||
Line 529: | Line 486: | ||
|- | |- | ||
| 09:59 | | 09:59 | ||
− | |Now | + | |Now click on '''Save'''. |
|- | |- | ||
Line 537: | Line 494: | ||
|- | |- | ||
| 10:04 | | 10:04 | ||
− | || Come back to the terminal .Let me clear the prompt. | + | || Come back to the terminal. Let me clear the prompt. |
|- | |- | ||
| 10:10 | | 10:10 | ||
− | |To compile | + | |To compile, type '''g++ space ifstmt.cpp space -o space if1''' |
|- | |- | ||
| 10:20 | | 10:20 | ||
− | |Here we have | + | |Here we have 'if1' because we don't want to overwrite the output parameter '''if '''for the file 'ifstmt.c'. |
|- | |- | ||
| 10:31 | | 10:31 | ||
− | |Now Press | + | |Now Press 'Enter'.To execute type '''./if1''' (dot slash if1) and press '''Enter'''. |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
|- | |- | ||
| 10:39 | | 10:39 | ||
− | |Enter the value of''' a''' and '''b'''. I will give the values as 20 and 10. | + | |Enter the value of '''a''' and '''b'''. I will give the values as 20 and 10. |
|- | |- | ||
| 10:48 | | 10:48 | ||
− | |The output is displayed as | + | |The output is displayed as '''Sum of a and b is 30''' |
|- | |- | ||
| 10:52 | | 10:52 | ||
− | |Sum is greater than 20 | + | |'''Sum is greater than 20''' |
|- | |- | ||
Line 574: | Line 527: | ||
| 10:59 | | 10:59 | ||
| Now come back to our slides. | | Now come back to our slides. | ||
+ | |||
|- | |- | ||
| 11:02 | | 11:02 | ||
Line 580: | Line 534: | ||
|- | |- | ||
| 11:04 | | 11:04 | ||
− | |In this tutorial we learned | + | |In this tutorial we learned 'if' statement eg. if(condition), |
− | + | ||
|- | |- | ||
| 11:11 | | 11:11 | ||
− | | And else if statement eg. else if(condition) | + | | And 'else if' statement eg. else if(condition). |
|- | |- | ||
| 11:17 | | 11:17 | ||
− | | As an assignment, | + | | As an assignment, Write a program to check 'a' is greater than 'b' or less than 'b'. |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
|- | |- | ||
| 11:24 | | 11:24 | ||
− | | | + | |Hint: use 'if' statement. |
|- | |- | ||
| 11:28 | | 11:28 | ||
− | |Write another program to check which value is greater '' | + | |Write another program to check which value is greater 'a', 'b' or 'c'. |
|- | |- | ||
| 11:34 | | 11:34 | ||
− | | | + | |Hint: use 'else-if' statement. |
|- | |- | ||
Line 633: | Line 582: | ||
|- | |- | ||
| 11:57 | | 11:57 | ||
− | |For more details, please write to, | + | |For more details, please write to, contact @ spoken hyphen tutorial dot org. |
|- | |- | ||
Line 649: | Line 598: | ||
|- | |- | ||
| 12:20 | | 12:20 | ||
− | | This is Ashwini Patil from IIT | + | | This is Ashwini Patil from IIT Bombay. |
Thank You for watching. | Thank You for watching. | ||
|} | |} |
Latest revision as of 11:17, 5 September 2017
Time | Narration |
00:02 | Welcome to the spoken tutorial on Conditional statements in C and C++. |
00:08 | In this tutorial we will learn: |
00:11 | How to execute a single statement |
00:14 | How to execute group of statements. |
00:16 | We will do this through examples. |
00:19 | We will also see some common errors and their solutions. |
00:25 | To record this tutorial, I am using Ubuntu Operating system version 11.10. |
00:31 | gcc and g++ Compiler version 4.6.1. |
00:38 | Let us start with the introduction to conditional statements. |
00:43 | A statement in a program controls the flow of program execution. |
00:49 | It helps to make decision on what code is to be executed. |
00:55 | We can check the conditions, whether true or false. |
01:00 | We can execute a single statement or a group of statements. |
01:07 | Let us understand the flow of if statements. |
01:13 | Here, if the condition is true then statement 1 will be executed. |
01:20 | If the condition is false then statement 2 will be executed. |
01:29 | Now we will see the flow of else if statement. |
01:32 | Here, if condition 1 is true then statement 1 will be executed. |
01:41 | If condition 1 is false then it will check for another condition that is condition 2. |
01:49 | If condition 2 is true then statement 3 will be executed. |
01:54 | And If condition 2 is false then statement 2 will be executed. |
02:02 | Now Let us move on to our program. |
02:06 | I have already typed the code on the editor. |
02:09 | So, let me open it. |
02:13 | Note that our file name is ifstmt.c. |
02:18 | In this program we will calculate the sum of two numbers and will check a few conditions. |
02:26 | Let me explain the code now. |
02:30 | This is our header file. |
02:34 | This is our main() function. |
02:38 | Here we have declared three integer variables a, b and sum. |
02:46 | Here we are asking for user input. |
02:49 | User will enter the values of a and b. |
02:52 | The values will be stored in variable a and variable b. |
02:58 | The scanf() function reads data from the console. |
03:02 | It then stores the result in the given variable. |
03:06 | The format specifier in the scanf() helps to know the type of data. |
03:10 | Like here we have %d, it denotes that we are dealing with integer data type. |
03:18 | Here we add the values of a and b. |
03:22 | We will store the result in sum. |
03:25 | Then we print the result. |
03:29 | This is our if statement. |
03:30 | Here, we check the condition whether sum is greater than 20. |
03:36 | If the condition is true, then we print Sum is greater than 20. |
03:42 | Now let me comment out these lines. |
03:48 | This is our return statement. |
03:51 | Now click on Save. |
03:53 | First we will see the execution of if statement. |
03:58 | Please open the terminal window by pressing Ctrl, Alt and T keys simultaneously on your keyboard. |
04:09 | To compile, type gcc space ifstmt dot c space -o space if and press Enter. |
04:20 | To execute, type ./if (dot slash if). Press Enter. |
04:26 | It is displayed as Enter the values of a and b. |
04:31 | I will give the values as 10 and 12. |
04:38 | The output is displayed as Sum of a and b is 22. Sum is greater than 20. |
04:45 | Now come back to our program. |
04:48 | We will check another condition. |
04:52 | Let me remove the comment from here. |
04:56 | I will give the comment here. |
05:00 | Now click on Save. This is our else-if statement. |
05:05 | Here, we check another condition whether Sum is greater than 10. |
05:11 | If the condition is true then we print 'Sum is greater than 10 and less than 20'. |
05:18 | Now come back to our terminal. |
05:20 | Let us compile as before. |
05:23 | Let us execute as before. |
05:26 | It is displayed as |
05:28 | Enter the value of a and b. |
05:30 | I will give the values as 10 and 2. |
05:35 | The output is displayed as: Sum of a and b is 12. |
05:38 | Sum is greater than 10 and less than 20. |
05:42 | Let me clear the prompt. |
05:44 | Now come back to our program. |
05:48 | I will remove the comment from here and here. Now click on Save. |
05:56 | If both the above conditions are false then we print 'Sum is less than 10'. |
06:04 | This is our else statement. |
06:07 | Now let us execute and see. Come back to our terminal. |
06:11 | Let us compile as before. Let us execute as before. |
06:18 | Here it is displayed as Enter the value of a and b. |
06:22 | I will give the values as 3 and 5. |
06:27 | The output is displayed as sum of a and b is 8. |
06:31 | Sum is less than 10. |
06:34 | Now we will see some common errors which we can come across. |
06:38 | Come back to our program. |
06:41 | Suppose, here at the end of if statement I will type a semicolon (;). |
06:47 | Let us see what will happen. Click on Save. |
06:50 | Let us execute. Come back to our terminal. |
06:53 | Let us compile as before. |
06:56 | We see an error: 'else' without a previous 'if' |
07:02 | Come back to our program. It is a syntax error. |
07:07 | if statement will never terminate with a semicolon. |
07:10 | And the else if statement will never work without an if. |
07:16 | Let us fix the error. Delete the semicolon (;) here. |
07:22 | Now Click on Save. |
07:25 | Let us execute. Come back to the terminal. |
07:29 | Let us compile as before. Let us execute as before. |
07:35 | Enter the value of a and b. |
07:37 | I will give the values as 3 and 6. |
07:43 | The output is displayed as |
07:45 | Sum of a and b is 9. Sum is less than 10. |
07:52 | NOW WE WILL SEE HOW TO EXECUTE THE SAME PROGRAM IN C++. |
07:57 | Come back to our program. |
07:59 | I will change a few things here. |
08:03 | Press Shift, Ctrl and S keys simultaneously on your keyboard. |
08:11 | Now save the file with an extension dot cpp and click on Save. |
08:20 | We will change the header file as iostream. |
08:26 | Let us include the using statement here. |
08:30 | Now click on the Search for and replace text option. |
08:35 | Let us replace the printf statement with the cout statement. |
08:40 | Click on Replace all and click on Close. |
08:46 | Now delete the closing brackets here. |
08:49 | Replace the scanf() statement with the cin statement. |
08:54 | Type cin and two closing angle brackets >>. |
09:00 | As we use cin >> function to read a line in C++. |
09:05 | Now delete the format specifiers. |
09:09 | Delete the comma and ampersand &. |
09:12 | Delete the comma here and type two closing angle brackets. |
09:17 | Again delete the ampersandand the closing brackets. Now click on Save. |
09:25 | Here delete the closing bracket and the comma. |
09:31 | Now delete the backslash n (\n) and format specifier. |
09:37 | Now type two opening brackets. |
09:42 | Again type two opening angle brackets and within the double quotes type backslash n “\n”. |
09:49 | Here also we will delete the closing bracket. |
09:53 | Now again delete the closing bracket here and here. |
09:59 | Now click on Save. |
10:02 | Let us execute. |
10:04 | Come back to the terminal. Let me clear the prompt. |
10:10 | To compile, type g++ space ifstmt.cpp space -o space if1 |
10:20 | Here we have 'if1' because we don't want to overwrite the output parameter if for the file 'ifstmt.c'. |
10:31 | Now Press 'Enter'.To execute type ./if1 (dot slash if1) and press Enter. |
10:39 | Enter the value of a and b. I will give the values as 20 and 10. |
10:48 | The output is displayed as Sum of a and b is 30 |
10:52 | Sum is greater than 20 |
10:56 | This brings us to the end of this tutorial. |
10:59 | Now come back to our slides. |
11:02 | Let us summarize. |
11:04 | In this tutorial we learned 'if' statement eg. if(condition), |
11:11 | And 'else if' statement eg. else if(condition). |
11:17 | As an assignment, Write a program to check 'a' is greater than 'b' or less than 'b'. |
11:24 | Hint: use 'if' statement. |
11:28 | Write another program to check which value is greater 'a', 'b' or 'c'. |
11:34 | Hint: use 'else-if' statement. |
11:38 | Watch the video available at the link shown below. |
11:41 | It summarizes the Spoken Tutorial project. |
11:44 | If you do not have good bandwidth, you can download and watch it. |
11:48 | The Spoken Tutorial Project Team, |
11:50 | Conducts workshops using spoken tutorials. |
11:54 | Gives certificates to those who pass an online test. |
11:57 | For more details, please write to, contact @ spoken hyphen tutorial dot org. |
12:04 | Spoken Tutorial Project is a part of the Talk to a Teacher project. |
12:09 | It is supported by the National Mission on Education through ICT, MHRD, Government of India. |
12:15 | More information on this Mission is available at the link shown below. |
12:20 | This is Ashwini Patil from IIT Bombay.
Thank You for watching. |
Contributors and Content Editors
Ashwini, Devraj, Kavita salve, Krupali, PoojaMoolya, Priyacst, Sakinashaikh, Sandhya.np14, Sneha