if else Statements in C++ | Part 1

Video

Task 1

Write a program that Accepts a character from user and checks if it is a lower case or not. If it is a lower case then print the message “ You Entered Lower Case Character”
Else “You didn’t Entered Lower case Letter”

Code

#include<iostream>
using namespace std;
int main()
{
	//variable required character type
	char ch;
	//input value
	cout<<"Enter any Alphabet : ";
	cin>>ch;
	//conditions to check if it is lower case of not
	if(ch>=97 && ch <=122)//ascii codes of lower case alphabets range from 97 to 122
	{
		cout<<"\nYou entered Lower case Character \n";
	}
	else
	{
		cout<<"\nYou Didn't Entered Lower Case Letter\n";
	}
}

Output

Enter any Alphabet : f

You entered Lower case Character

Task 2

Write a program that ask the user to enter a number and check if it is positive, negative or zero

Output

#include<iostream>
using namespace std;
int main()
{
	//input variable int type
	int n;
	//taking input
	cout<<"Enter Value : ";
	cin>>n;
	//conditions
	if(n<0)
		cout<<"\nNumber is Negative \n";
	else if(n>0)
		cout<<"\nNumber is Positive \n";
	else
		cout<<"\nNumber is equal to zero";
}

Output

Enter Value : -10

Number is Negative

Related Post

1 Comment

Leave a Reply

Your email address will not be published. Required fields are marked *