Basic programming course: Lesson #4 Control structures. Part 1. Conditionals.

in Steem4Professionals14 hours ago

Steemian Friends,
Today, I will write a teaching assignment for @alejos7ven sir in Week 04 of Teaching Engagement Challenge Session 20. The subject is Basic programming course: Lesson #4 Control structures. Part 1. Conditionals. I hope everyone will like my writing.

Basic programming course (1).png
Design By Canva

Homework

Describe your understanding of conditional structures and mention 2 situations of everyday life where you could apply this concept.

Programming Conditional Structure:
To solve any problem with computer programming language, it is necessary to solve the task with conditions. There are different types of conditions in computer programming. As an example, I will write about If and If else conditions today. There are several other conditional statements in computer programming. Complex problems can be solved easily through conditional statements.

If Conditional Structure:

A condition is given through the If structure. If the function is true, then the code will execute, and if false, then the code will stop. I have given an example of an if-conditional structure below and used the If condition to find an even and odd number. The If condition will execute if the number typed is even. Again, the next If condition will work if it is odd.


if (num1>num2)
printf("Large = %d\n", num1);


#include<stdio.h>
int main()
{
int num;
printf("Enter an integer : ");
scanf("%d",& num);
{
if(num%2==0)
printf("Even\n");
if(num%2!=0)
printf("odd\n");
}
return 0;
}


if.png

Else Condition:

Like If, ​​else is a conditional statement. Suppose the If condition is not true then the else condition will execute. Below I have shown an else condition as an example.


else
printf("odd\n");


#include<stdio.h>
int main()
{
int num;
printf("Enter an integer : ");
scanf("%d",& num);
{
if(num%2==0)
printf("Even\n");
else
printf("odd\n");
}
return 0;
}


else.png


For example, two input numbers are the same; the else condition is executed instead of the If condition, and the other condition is executed as the output.


#include<stdio.h>
int main()
{
int num1, num2;
printf("Enter first number : ");
scanf("%d", &num1);
printf("Enter second number : ");
scanf("%d", &num2);
if (num1>num2)
printf("Large = %d\n", num1);
if (num1<num2)
printf("Large = %d\n", num2);
else
printf("Number are equal");
return 0;
}


ifelse.png


Create a program that tells the user "Welcome to the room What do you want to do?", if the user writes 1 then it shows a message that says "you have turned on the light", if the user writes 2 then it shows a message that says "you have left the room". Use conditionals.

The program uses if-and-else conditions. After typing 1, the program's output will show the text "You have turned on the light. " If you type 2 again, the program's output will show "You have left the room."


#include<stdio.h>
int main()
{
int x;
printf("Enter the value of x: \n");
scanf("%d", &x);
if(x == 2)
{
printf("Welcome to the room what do you want to do\n");
printf("You hsve turned on the light\n");
else
{
printf("Welcome to the room what do you want to do\n");
printf("You have left the room\n");
}
return 0;
}


light on the.png


#include<stdio.h>
int main()
{
int x;
printf("Enter the value of x: \n");
scanf("%d", &x);
if(x == 1)
{
printf("Welcome to the room what do you want to do\n");
printf("You hsve turned on the light\n");
else
{
printf("Welcome to the room what do you want to do\n");
printf("You have left the room\n");
}
return 0;
}


left the room.png


Create a program that asks the user for 4 different ratings, calculate the average and if it is greater than 70 it shows a message saying that the section passed, if not, it shows a message saying that the section can improve.

The homework condition was 70 marks high for the program by making four ratings. I created the program by calculating the grades of our country's education system. I apologize for making my condition slightly different from yours.


MarksGrade
80-100A+
70-80A
60-70A-
50-60B
40-50C
33-40D
0-33Fail


#include< iostream >
using namespace std;
int main()
{
int mark;
cout<<"Enter mark:";
cin>>mark;
if(mark>100)
{
cout<<"Invalid mark";
}
else if (mark<0)
{
cout<<"Invalid mark";
}
else if (mark>=80)
{
cout<<"A+";
}
else if (mark>=70)
{
cout<<"A";
}
else if (mark>=60)
{
cout<<"A-";
}
else if (mark>=50)
{
cout<<"B";
}
else if (mark>=40)
{
cout<<"C";
}
else if (mark>=33)
{
cout<<"D";
}
else
{
cout<<"Fail"<<endl;
}
}

marks.png


I input a student's mark of 67, and the grade is A-conditional.

Blue line.png

SL No.My Invited Steemit Friends
1@memamun
2@shahariar1
3@max-pro

Steemit.com.png

Sort:  

Upvoted. Thank You for sending some of your rewards to @null. It will make Steem stronger.

Coin Marketplace

STEEM 0.19
TRX 0.16
JST 0.030
BTC 63312.28
ETH 2601.44
USDT 1.00
SBD 2.79