Skip to main content

Conditional Statements in C++


Conditional Statements in C++

If Statement

If Statement is used to check the Condition. If the Condition is True then It will enter into the if block and perform the operations. If the Condition is Flase then it will terminate the Program.

Syntax

if (condition)
{
       Statements;
}

Flow Chart

























If Else Statement

In this If the Condition is True then It will enter into the if block and perform the operations. If the Condition is False then it will enter into else block and execute the Statements.

Syntax

if (condition)
{
       Statements;
}
else
{
       Statements;
}

Flow Chart
























If Else If Statement

It is used when we have multiple Conditions. In this If the Condition is True then It will enter into the if block and perform the operations. If the Condition is False then it will check another condition and so on.

Syntax

if (condition)
{
       Statements;
}
else if(condition)
{
       Statements;
}
.
.
.
else
{
      Statements;
}

Flow Chart



























Nested If Statement

It is used Check conditions step wise . In this If the Condition is True then It will enter into the if block and then it will check another condition and executes the statements. If the Condition is False will enter into else block and executes the statements.And this goes so on.

Syntax

if (condition)
{
     if(condition)
     {
       Statements;
      }
      else
     {
        Statements;
     }
}
else
{
       Statements;
}

Flow Chart







Switch Statements

It is used for multiway banching statements. In this the condition is matched based on cases.

Syntax

switch(choice)
{
    case Number/'Character':
Statements;
break;
.
.
.
.
case N:
Statements;
               break;
default:
Statements;
}

Programs

If Condition

WAP to check the entered number is Even?


















If-else Condition

WAP to check the entered number is Even or Odd?






















If-else-if Condition

Write a program to evaluate the Grade of a student for the following constraints:
If marks > 75 – grade A
If 60 < marks < 75 – grade B
If 45 < marks<60 – grade C
If 35 < marks<45 - grade D
If marks < 35 – grade E




















Nested If Condition

WAP to check the entered number is Even or Odd and Number Should be Greater than 10?























Nested If Condition

Write Program to show the Working of Switch Statement using a Basic Calculator Program?

Comments

Popular posts from this blog

Programming Basics

Logic Building Data_Types Operators Algorithms Pseudo_Code Hello Guys, Let's Play with Logic.........but wait, before that you must know that how to build Logic in Programming as you all know that programming is all about Logic..... So Let's start the game... If you are new Here that means you are absolutely right Place, Or If you already know, than you will learn new things here! If we Talk about the Programming we should be familiar with  these terms..... 1. Variable 2. Data Types 3.Keywords Variable: Variable is something which holds the value.                  Like:      a=10;                 Here,                 a---------------------->  Variable                  10 ---------------------> Value * The Value of Variable can be changed , *  " Variable is a named memory Location which holds a value." Data Types:   Data Type is what which tells that which kind of data we are using. In programming we have different Dat

FAQs

Basic Questions on Programming Languages 1. What is the meaning of Programming? Ans: Programming is the process of Scheduling the task to perform step by step to Execute a specific Task. 2. Types of Programming Languages? Ans: Types:             Procedural Programming Language            Object Oriented Programming Language            Object Based Language            Scripting Language Procedural Programming Language   C Programming  Object Oriented Programming Language     C++     Java     C#     VB.Net Object Based Language     JavaScript Scripting Language     Python     VBScript     PHP     Perl     Ruby     R 3. Types Of Operators in Programming Languages. Ans:      Operators Symbols Type Example Assignment = Unary a=10 Arithmetic +,-,/,*,% Binary a+b  a-b  a*b  a/b  a%b Relational >, <, >=, <=, ==, !=(Not Equal) Binary It gives Result in Boolen value True/False a>b  a<b  a>=b  a<=b  a==b  a!=b Logical && (AND), ||(OR), !(Not) Binary It gives Resul