Learning C++ : If-else statement
Hello Friends !!
My name is Wajahat Sardar and today i am going to discuss about decision making statement in a C++ program i,ll discuss about If-else statement.
- If statement.
- If-else statement
- Else-if statement
- Nested if-else statement
C++ If-else Statement.
if(test-expression)
{
//Statement / statements ;
}
else
{
//Statement / statements ;
}
How if-else statement work
- if test-expression inside the if parenthesis is true, then the statements inside the body of if is executed.
- if the test-expression inside then if parenthesis is false, then the statement inside the if body is skipped and control goes to the else statement and else statement executes.
Flow chart
Simple if-else program
#include <iostream>
using namespace std;
int main() // Most important part of the program!
{
int age; // Need a variable...
cout<<"Please input your age: "; // Asks for age
cin>> age; // The input is put in age
if ( age <= 30 ) { // If the age is less than 100
cout<<"You are pretty young!\n"; // Just to show you it works..
}
else {
cout<<"You are really old\n"; // Executed if no other statement is
}
return 0
}
Output :
Please input your age: 20
You are pretty young!
I hope you will like this.
https://steemit.com/introduceyourself/@wajahatsardar/about-me-who-am-i
https://steemit.com/science/@wajahatsardar/learn-to-code-nested-if-else-statement-in-c
Follow @wajahatsardar
Please do not use the #introduceyourself tag for anything other than your own introductions.
i got it
Welcome to Steem Community @wajahatsardar! As a gentle reminder, please keep your master password safe. The best practise is to use your private posting key to login to Steemit when posting; and the private active key for wallet related transactions.
In the New Steemians project, we help new members of steem by education and resteeeming their articles. Get your articles resteemed too for maximum exposure. You can learn more about it here: https://steemit.com/introduceyourself/@gaman/new-steemians-project-launch
img credz: pixabay.com
Nice, you got a 15.0% @tincho upgoat, thanks to @wajahatsardar
Want a boost? Minnowbooster's got your back!
The @OriginalWorks BETA V2 bot has upvoted(0.5%) and checked this post!
Some similarity seems to be present here:
https://www.cprogramming.com/tutorial/c/lesson2.html
This is an early BETA version. If you cited this source, then ignore this message! Reply if you feel this is an error.
All the coding or program look similar to each other. the program i write is little similar to it. and the all work is done by me on my post.
thnaks for sharing this
your are well come
Enjoy your Steemit journey!
thanks !!!