C++ program to input basic salary of an employee and calculate its Gross salary.

#include <iostream>

#include links our program to the iostream library or it will make iostream library available for our use.

After including iostream, we are ready to use cout in our program.

#include<iomanip>

The setw() method of iomanip library in C++. It used to set the width based on the width specified in parameters.

float basic,gross,da,hra;

float -float is used for display the numbers as a decimal value.While integer(int) only displays the rounded value.

else if statement

Syntax

if (condition1) {
// block of code to be executed if condition1 is true
}

else if (condition2)

{
// block of code to be executed if the condition1 is false and condition2 is true
} else

{
// block of code to be executed if the condition1 is false and condition2 is false
}

else if statement is used to specify a new condition if a first condition is false.

Code:

setw() function:

This function accepts n as a parameter to set the width of the corresponding field.

cout<<setw (25) << “Basic Pay “<<setw (10)<< basic<<endl;

Full Code:

Output:

output 1
output 2

Refer GUVI to learn more about c++.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store