#7 Nested if syntax | what is a nested if statement | if multiple conditions | nested if example

preview_player
Показать описание
we will learn #nested #if #else statements in c++ in #urdu #hindi multiple if else if else nested

----------------------------------------------------------------------------------

Asignment Question 2 Corrected!!

Input a number from user, If number is less than 50,
add 100 in it... otherwise subtract 10 from it

Input another number from user, If number is greater than one, multiply it with 10 otherwise, multiply it with 20.

Input an operator(+,-,*,/) from user
If user enter +.. display sum on screen
If user enter - display there substraction on screen
SAME FOR OTHER Operators!!

----------------------------------------------------------------------------------

what is a nested if statement if else else
nested if syntax
nested if example
nested if and statements
multiple conditions in if statement
nested if else example nested statement multiple if statements nested if else statement in c
nested if statement example
Рекомендации по теме
Комментарии
Автор

Question No 2 Part No 1
# include <iostream>
using namespace std;
int main()
{
int num1, num2;
int a, b;
cout << "Enter an first number : ";
cin >> num1;

if (num1 < 50)
{
a = num1 + 100;
cout << "Number has been added by 100 : " << "Result = " << a << endl;
}

else
{
a = num1 - 10;
cout << "Number has been subtracted by 10 : " << "Result = " << a << endl;
}

Question No 2 Part No 2


cout << "Enter an second number : ";
cin >> num2;


if (num2 % 2 == 0)
{
b = num2 * 20;
cout << "The number has been multiplied by twenty " << b << endl;
}

else
{
b = num2 * 10;
cout << "The number has been multiplied by ten " << b << endl;
}



// Menu
cout << "Enter the first operator '+' " << endl;
cout << "Enter the second operator '-' " << endl;
cout << "Enter the third operator '*' " << endl;
cout << "Enter the fourth operator '/' " << endl;
cout << "Enter the fifth operator '%' " << endl;

char op;
cout << "Enter the operator : ";
cin >> op;

// 1
if (op == '+')
{
cout << "Sum of two numbers are " << a + b << endl;
}

// 2
else if (op == '-')
{
cout << "Subtract of two numbers are " << a - b << endl;
}

// 3
else if (op == '*')
{
cout << "Product of two numbers are " << a * b << endl;
}

// 4
else if (op == '/')
{
cout << "Division of two numbers are " << a / b << endl;
}

// 5
else if (op == '%')
{
cout << "Remainder of two numbers are " << a % b << endl;
}

else
{
cout << "Invalid Number " << endl;
}
return 0;
}



done it perfectly

muhammadhamzaatif
Автор

Q # 2 Done!!!
Check !

#include<iostream>
using namespace std;
int main()
{
int num;
cout<<"Enter a Number"<<endl;
cin>>num;

if(num<50)
{
int a;
a = num + 100;
cout<<a<<endl;
}
else if(num>50)
{
int b;
b = num - 10;
cout<<b<<endl;
}

int anothnum;
cout<<"Enter an another number"<<endl;
cin>>anothnum;

if(anothnum%2==0)
{
int x;
x = anothnum * 20;
cout<<x<<endl;
}
else
{
int y;
y = anothnum * 10;
cout<<y<<endl;
}

char op;
cout<<"Enter the Operater"<<endl;
cin>>op;

if(op=='+')
{
char sum;
cout<<"sum"<<endl;
}
else if(op=='-')
{
char Subtract;
cout<<"Subtract"<<endl;
}
else if(op=='*')
{
char multiply;
cout<<"multiply"<<endl;
}
else if(op=='/')
{
char Divide;
cout<<"Divide"<<endl;
}
else if(op=='%')
{
char Remainder;
cout<<"Remainder"<<endl;
}
else
{
cout<<"Input Valid...!!!"<<endl;
}
}

MuhammadYousaf-icrp
Автор

Q#2 Part 1
#include <iostream>

using namespace std;

int main()
{
int num;
cout<<"enter number"<<endl;
cin>>num;

if(num < 50)
{
num = num +100;

cout<<"your number is = "<<num<<endl;
}
else
{
num =num - 10;

cout<<"your number is = "<<num<<endl;
}

junaidalamjun
Автор

Question No 2 :- 1st part:
#include<iostream>
using namespace std;
int main()
{
int a, b, sum, sub;
cout<<"Enter the number :"<<endl;
cin>>a;
if(a<50)
{
sum=a+100;
cout<<"The Answer is ="<<sum;
}
else
{
sub=a-10;
cout<<"The Answer is ="<<sub;
}
}


2nd Part:-
#include<iostream>
using namespace std;
int main()
{
int a, b;
char op;
cout<<"Please Enter the First value: \n";
cin>>a;
if (a<50)
{

a = a+100;
cout<<a;
}
else
{

a= a-10;
cout<<a<<endl;
}
cout<<"Please Enter the Second value :"<<endl;
cin>>b;
if(b%2==1)
{
b=b*10;
cout<<b<<endl;
}
else
{
b=b*20;
cout<<b<<endl;
}
cout<<"Choose the operator you want to apply in the program"<<endl;
cout<<" + - * / % "<<endl;
cin>>op;
if(op=='+')
{
cout<<a+b;
}
else if(op=='-')
{
cout<<a-b;
}
else if(op=='*')
{
cout<<a*b;
}
else if(op=='/')
{
cout<<a/b;
}
else if(op=='%')
{
cout<<a%b;
}

}

muhammadmujtaba
Автор

dear public please like all these videosand also shere . thanks . sir i am vary thankfull to you

saddamhussain-ybid
Автор

Thank you sir so easy teaching I like it.

Quoteswithus
Автор

Am watch your videos that to much easy for us... Thanks for this.. 💗😊

musicbox
Автор

Masha Allah bhai bht acha samjha rahe ho.well done JAZAK ALLAH

ummeanaya
Автор

Q#2:
Solution:
#include<iostream>
using namespace std;
int main()
{
int a;
int b;
int num1;
cout<<"Please enter a number: ";
cout<<endl;
cin>>num1;

if (num1<50)
{
cout<<"The given number is less than 50, therefore"<<endl;
a= num1+100;
cout<<a;
cout<<endl;
}

else
{
cout<<"The given number is greater than 50, therefore"<<endl;
a= num1-10;
cout<<a;
cout<<endl;
}

int num2;
cout<<"Please enter a number:";
cout<<endl;
cin>>num2;

if (num2%2==1)
{
cout<<"The given number is odd, therefore"<<endl;
b=num2*10;
cout<<b;
cout<< endl;
}

else
{
cout<<"The given number is even, therefore"<<endl;
b=num2*20;
cout<<b;
cout<< endl;
}

char operation;
cout<<"Please enter an operation: ";
cout<<endl;
cin>>operation;

if (operation=='+')
{
cout<<"Addition";
cout<<endl;
int addition;
addition= a+b;
cout<< addition;
cout<<endl;
}

else if (operation=='-')
{
cout<<"Subtraction";
cout<<endl;
int subtraction;
subtraction= a-b;
cout<<subtraction;
cout<< endl;
}

else if (operation=='*')
{
cout<<"Multiplication";
cout<< endl;
int multiplication;
multiplication= a*b;
cout<<multiplication;
cout<< endl;
}

else if (operation=='/')
{
cout<<"Division";
cout<<endl;
int division;
division= a/b;
cout<<division;
cout<<endl;
}

else if (operation=='%')
{
cout<<"Remainder";
cout<<endl;
int remainder;
remainder= a%b;
cout<< remainder;
cout<< endl;
}

else
{
cout<<"Error";
cout<<endl;
}
return 0;
}

userbxhj
Автор

Q#1
#include <iostream>

using namespace std;

int main ()
{
int num1;
int num2;
int num3;
int num4;
int num5;
int num6;
int num7;
int num8;
int num9;
int num10;
int num11;

cout<<"ONE" <<endl;
cin>>num1;

cout<<"TWO" <<endl;
cin>>num2;

cout<<"THREE" <<endl;
cin>>num3;

cout<<"FOUR" <<endl;
cin>>num4;

cout<<"Five" <<endl;
cin>>num5;

cout<<"Six" <<endl;
cin>>num6;

cout<<"SEven" <<endl;
cin>>num7;

cout<<"Eight" <<endl;
cin>>num8;

cout<<"Nine" <<endl;
cin>>num9;

cout<<"Ten" <<endl;
cin>>num10;

cout<<"Error" <<endl;
cin>>num11;

return 0;
}

zainikhalid
Автор

#include<iostream>
using namespace std;

int main()
{
int num;
cout<<"Enter a number";
cin>>num;
if(num<50)
{
num = num+100;
cout<<num;
}
else {
num = num-10;
cout<<num;
}
}

Ruqyah
Автор

Please design a program that uses if-else statements and conditional operators to solve a real-world problem.

KehkshanAfzal-sc
Автор

Assignment 2
#include<iostream>
#include<iomanip>
#include<conio.h>
using namespace std;
int main()
{
int num;
cout<<"Enter a number :: ";
cin>>num;
cout<<"\n your number is :: "<<num<<endl<<endl;
if(num > 50)
{
cout<<num-10;
}
else if(num < 50)
{
cout<<num+100;
}
else
{
cout<<"number is equal";
}
}

SISAAF
Автор

Question 2 complete:
#include <iostream>
using namespace std;
int main()
{
int num1;
cout<<"enter the first number"<<endl;
cin>>num1;

if(num1<50)
{
cout<<"your number has been added by 100"<<endl;
cout<<num1+100<<endl;
}
else
{
cout<<"your number has been substracted by 10"<<endl;
cout<<num1-10<<endl;
}

int num2;
cout<<"enter the second number"<<endl;
cin>>num2;

if(num2%2!=0)
{
cout<<"mutiply num2 with 10"<<endl;
cout<<num2*10<<endl;
}

else
{
cout<<"multiply num2 with 20"<<endl;
cout<<num2*20<<endl;
}

char oper;
cout<<"enter an operator, +, -, *, /, %, "<<endl;
cin>>oper;

if(oper=='+')
{
cout<<"sum";
}

else if(oper=='-')
{
cout<<"substract";
}

else if(oper=='*')
{
cout<<"multiply";
}

else if(oper=='/')
{
cout<<"division";
}

else
{
cout<<"remainder";
}

return 0;
}

Anasmeo-xpqn
Автор

q(b)
#include<iostream>
using namespace std;
int main(){
int num;
cout<<"Enter a number: ";
cin>>num;
if(num%2==1){
num*=20;
}
else{
num*=10;
}
cout<<"The new value of the number is: "<<num<<endl;
}

javeriafazal
Автор

Assignment 1
#include<iostream>
#include<iomanip>
#include<conio.h>
using namespace std;
int main()
{
cout<<"Enter a number :: ";
int num;
cin>>num;
if(num == 1)
{
cout<<"one";
}
else if(num == 2)
{
cout<<"two";
}
else if(num == 3)
{
cout<<"Three";
}
else if(num == 4)
{
cout<<"Four";
}
else if(num == 5)
{
cout<<"five";
}
else if(num == 6)
{
cout<<"six";
}
else if(num == 7)
{
cout<<"seven";
}
else if(num == 8)
{
cout<<"eight";
}
else if(num == 9)
{
cout<<"nine";
}
else if(num == 10)
{
cout<<"ten";
}
else
{
cout<<"invalid";
}
}

SISAAF
Автор

Question No#02

#include<iostream>
using namespace std;
int main()
{
int n1, n2, a, b;


cout<<"enter a number 1"<<endl;
cin>>n1;

if(n1<50)
{

cout<<"number is less then 50 add 100"<<endl;
a=n1+100;
cout<<"a is =" <<a<<endl;
}

else
{

cout<<"number is greater then 50 sub 10"<<endl;
a=n1-10;
cout<<"number is = "<<a<<endl;
}

cout<<"enter a number 2"<<endl;
cin>>n2;

if(n2%2==1)
{
cout<<"number is odd mult with 10"<<endl;
b=n2*10;
cout<<"number is ="<<b<<endl;
}

else
{
cout<<"number is even mult with 20"<<endl;
b=n2*20;
cout<<"number is ="<<b<<endl<<endl;
}

cout<<"Please select the optaion"<<endl<<endl;
cout<<"Press 1 for sum"<<endl;
cout<<"Press 2 for Subtract"<<endl;
cout<<"Press 3 for multiply"<<endl;
cout<<"Press 4 for Divide"<<endl;
cout<<"Press 5 for Remainder"<<endl;


int op;
cin>>op;


if(op==1)
{
int sum;
sum=a+b;
cout<<"sum ="<<sum<<endl;

}

else if(op==2)
{
int sub;
sub=a-b;
cout<<"Subtract ="<<sub<<endl;
}

else if(op==3)
{
int mul;
mul=a*b;
cout<<"multiply ="<<mul<<endl;
}

else if(op==4)
{
int div;
div=a/b;
cout<<"Divide ="<<div<<endl;
}

else if(op==5)
{
int rem;
rem=a%b;
cout<<"Remainder ="<<rem<<endl;
}
else
{
cout<<"Input Valid...!!!"<<endl;
}

}

mzee
Автор

Thank you so much sir solve question in chart box

sanjaykumarpandey
Автор

assalam o alaikum shazaib bhai
bhai drasal hame masla hi statement ko code me convert me huraha to kindly statement ko code me convert krne k related btadein (thnks)

umairahmed
Автор

1st Question:
#include<iostream>
using namespace std;
int main ()
{
int num;
cout<<"Please enter the number:"<<endl;
cin>>num;
if(num==1)
{
cout<<"One"<<endl;
}
else if (num==2)
{
cout<<"Two"<<endl;
}
else if (num==3)
{
cout<<"Three"<<endl;
}
else if (num==4)
{
cout<<"Four"<<endl;
}
else if (num==5)
{
cout<<"Five"<<endl;
}
else if (num==6)
{
cout<<"Six"<<endl;
}
else if (num==7)
{
cout<<"Seven"<<endl;
}
else if (num==8)
{
cout<<"Eight"<<endl;
}
else if (num==9)
{
cout<<"NIne"<<endl;
}
else if (num==10)
{
cout<<"Ten"<<endl;
}
else
{
cout<<"Error"<<endl;
}



return 0;
}

Output 1:
Please enter the number:
7
Seven


Process exited after 3.545 seconds with return value 0
Press any key to continue . . .

Output 2:
Please enter the number:
11
Error


Process exited after 3.956 seconds with return value 0
Press any key to continue . . .

muhamamdsalman
join shbcf.ru