Syntax:
#include<iostream>
using namespace std; //header
files
void main()
{
if(conditon
1)
{
// body of
if
}
else if(condition
2)
{
// body of
else if
}
else if(condtion
3)
{
// body of else if
}
else
{
// body of
else
}
system("pause");
}//body of main.
Example of If else If
Write a c++ program in which user give the marks of a student and the program assign him the grades.
The criteria is given bellow.
if marks >=90 then Grade A+
if marks >=80 then Grade A
if marks >=70 then Grade B+
if marks >=60 then Grade B
if marks >=50 then Grade c
if marks <=40 then Grade F
Solution:
#include<iostream>
using namespace std; //header files
void main()
{
int a; //declare a variable a. cosider it veriable for taking
marks.
cout<<"Enter your marks
:"<<endl; //message
cin>>a;
//taking input from
the user.
if(a>=90)// this condition will
compare a with the 90 or greater values.
{
cout<<" Your grade is A+"<<endl;
}
else if(a>=80)// this condition will compare a with the 80 or
greater values but less then 90.
{
cout<<" Your grade is A "<<endl;
}
else if(a>=70)// this condition will
compare a with the 70 or greater values but less then 80.
{
cout<<" Your grade is B+ "<<endl;
}
else if(a>=60)// this condition will
compare a with the 60 or greater values but less then 70.
{
cout<<" Your grade is B "<<endl;
}
else if(a>=50)// this condition will
compare a with the 50 or greater values but less then 60.
{
cout<<" Your grade is C "<<endl;
}
else if(a>=30)// this condition will
compare a with the values less then 40.
{
cout<<" Your grade is F "<<endl;
}
else
{
cout<<" Invalid input.."<<endl; //when user enter any
character or invalid value...
}
cout<<"\n\n\n"<<endl; //used for next line.
system("pause");
}//body
of main.
TAGS:
if, programming, else, structure, java, if else, tutorial, decision, conditional, elseif, then, excel vba tutorial, excel vba example, excel vba examples, code, vb, science, computer, c++, if-else, control flow, control, visual studio, visual basic, condition, control structure, c language, learn java, java tutorial, branching statements, decisions, javascript, syntax, conditions, php, if else statement, structures, how to program, control structures, c (programming language), statement, vba, c programming, beginners, python, language, or, basic, script, nested if, simple if, introduction, else if, 2010, control structures in c++, java if else, if statements, visual basic for applications, features, high-level, kanthety, saradhi, sundeep, java tutorials, flowchart, how to use for loop in java, how to use for loop in laravel, how to use for loop in android studio, how to use for loop in c++, how to use for loop in excel, how to use for loop in jquery, how to use for loop in php, if-else block, branching, matlab, if conditions, java branching, java programming, if block, c program, pgc lectures:, java example, mechanical engineering, microsoft excel (software), university, java course, how to, statements, learn to code, indentation, coding, scripting language, lectures, how to use for loop in javascript, how to use for loop in matlab, how to use for loop in c programming, how to use for loop in python, how to use for loop in vba, how to use for loop in c++ in hindi,
No comments:
Post a Comment