Write a program that inputs salary and grade. It adds 50% bonus if the grade is greater than 15. It adds 25% bonus if the grade is 15 or less and then displays the total salary.
Answers
Explanation:
if-else’ statement
If else statement is another type of if statement. It executes one or block of statements when the condition is true and the other when it is false. In any situation, one block is executed and the other is skipped. In if else statement:
· Both block of statements can never be executed.
· Both block of statements can never be skipped.
Syntax
if(condition)
statement;
else
statement;
For compound statements
if(condition )
{
Statement1;
Statement2;
.
.
.
Statement n;
}
else
{
Statement1;
Statement2;
.
.
.
Statement n;
}
Flow chart:
/*write a program that inputs a number and finds whether it is even or oddusing if - else statement.*/
#include <iostream.h>
#include <conio.h>
main()
{
int n;
cout<<"Enter a number \n";
cin>>n;
if( n % 2 == 0)
cout<<"The number is even\n";
else
cout<<"The number is \a odd\n";
getche();
}
/*write a program that inputs a year and finds whether it is leap year or not.by using if-else statement.*/
#include <iostream.h>
#include <conio.h>
main()
{
int year;
cout<<"Enter the year \n";
cin>>year;
if( year % 4 == 0)
cout<<"The entered year is leap year \a \n";
else
cout<<"The entered year is not leap year\n";
getche();
}
/*write a program that inputs salary and grade. it adds 50% bonus if the grade is
greater than 15 . it adds 25% bonus if the grade is 15 or less and then displays the total salary. */
#include <iostream.h>
#include <conio.h>
main()
{
float slry, bonus;
int grde;
cout<<"Enter your salary\n";
cin>>slry;
cout<<"Enter your grade\n";
cin>>grde;
if(grde > 15)
{
slry = slry + 0.50 * slry;
cout<<"Your total salary is = "<<slry<<endl;
}
Else
{
slry = slry + 0.25 * slry;
cout<<"Your total salary = "<<slry<<endl;
}
getche();
}
/*write a program that inputs two integers and determines and prints if
the first integer is the multiple of second integer.*/
#include <iostream.h>
#include <conio.h>
main()
{
int n, n1;
cout<<"Enter two numbers\n";
cin>>n>>n1;
if( n % n1 == 0)
cout<<"The first number is the multiple of the second\n";
getche();