[Solved] Salary Computation with Java, C++, Python

Salary Computation: Danny has recently got his job offer as an Event Concept Creator at Sparsh Event Services. The Company has sent him a detailed salary structure with details of his basic salary, HRA and DA. The Company has promised to pay him as under:

If his basic salary is less than Rs. 15000, then HRA = 15% of basic salary and DA = 90% of basic salary.
If his basic salary is either equal to or above Rs. 15000, then HRA = Rs. 5000 and DA = 98% of basic salary.

If the Danny’s salary is given as input, write a program to find his gross salary.

Note : Gross Salary = Basic Salary+HRA+DA

Input Format:
First line of the input is an integer that corresponds to the basic salary of Danny.

Output Format:
Output should display the double value that refers to the gross salary of Danny. Display the output correct to 2 decimal places.
Refer sample input and output for formatting specifications.

Sample Input 1:
12000

Sample Output 1:
24600.00

Sample Input 2:
30000

Sample Output 2:
64400.00

Solution

import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        //sauravhathi
        if (n < 15000) {
            System.out.printf("%.2f", n+n*0.15+n*0.9);
        } else {
            //sauravhathi
            System.out.printf("%.2f", n+5000+n*0.98);
        }
    }
}
#include<iostream>
using namespace std;
int main()
{
    int n;
    cin>>n;
    if(n<15000)
    {
        printf("%.2f",n+n*0.15+n*0.9);
    }
    else
    {
        printf("%.2f",n+5000+n*0.98);
    }
    return 0;
}
n = int(input())
if n < 15000:
    print("{:.2f}".format(n+n*0.15+n*0.9))
else:
    print("{:.2f}".format(n+5000+n*0.98))

Happy Learning – If you require any further information, feel free to contact me.

Share your love
Saurav Hathi

Saurav Hathi

I'm currently studying Bachelor of Computer Science at Lovely Professional University in Punjab.

📌 Nodejs and Android 😎
📌 Java

Articles: 444

Leave a Reply

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