Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can somebody see if this code is right? Here\'s the problem: Write a program tha

ID: 3649020 • Letter: C

Question

Can somebody see if this code is right?

Here's the problem:

Write a program that calculates and prints the monthly paycheck for an employee.

When I compiled and ran it, I typed the employee name and the gross amount but the results didn't print out. What's the reason for this?

#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>

using namespace std;

int main(int argc, char *argv[])
{
// define the constants
const double Fed_tax = 15;
const double State_tax = 3.5;
const double Social_Security_Tax = 5.75;
const double Medicare_tax = 2.75;
const double PENSION = 5;
const double Health_insurance = 75;

// define the variables
double gross, federaltax, statetax, sstax;
double medicaretax, Pension, netPay;
string name;
ofstream outFile;

// This let's the user know what this program is all about
cout <<" Program that prints monthly paycheck.";

// prompts the user to enter their name and their gross amount
cout << " Enter employee name: ";
cin >> name;
cout << " Enter gross amount: ";
cin >> gross;

// Begin calcuations
federaltax = gross * Fed_tax / 100;
statetax = gross * State_tax / 100;
sstax = gross * Social_Security_Tax / 100;
medicaretax = gross * Medicare_tax / 100;
Pension = gross * PENSION / 100;
netPay = gross -
(federaltax +
statetax +
sstax +
medicaretax +
Pension +
Health_insurance);

// open the output file
outFile.open("outdata.txt");

cout << fixed << showpoint;

cout << setprecision(2);

// This will display the paycheck details, which is written into the file
outFile << name << endl;
outFile << setw(25) << left << setfill ('.')
<< "Gross Amount:" << " $"
<< setw(10) << right << setfill (' ')
<< gross << endl;
outFile << setw(25) << left << setfill ('.')
<< "Federal Tax:" << " $"
<< setw(10) << right << setfill (' ')
<< federaltax << endl;
outFile << setw(25) << left << setfill ('.')
<< "State Tax:" << " $"
<< setw(10) << right << setfill (' ')
<< statetax << endl;
outFile << setw(25) << left << setfill ('.')
<< "Social Security Tax:" << " $"
<< setw(10) << right << setfill (' ')
<< sstax << endl;
outFile << setw(25) << left << setfill ('.')
<< "Medicare/Medicaid Tax:" << " $"
<< setw(10) << right << setfill (' ')
<< medicaretax << endl;
outFile << setw(25) << left << setfill ('.')
<< "Pension Plan:" << " $"
<< setw(10) << right << setfill (' ')
<< Pension << endl;
outFile << setw(25) << left << setfill ('.')
<< "Health Insurance:" << " $"
<< setw(10) << right << setfill (' ')
<< Health_insurance << endl;
outFile << setw(25) << left << setfill ('.')
<< "Net Pay:" << " $"
<< setw(10) << right << setfill (' ')
<< netPay << endl;

outFile.close();
system("PAUSE");
return EXIT_SUCCESS;
}

Explanation / Answer

Your program should prompt the user to input the employee name and the gross amount. The out put will be stored in a file. Format your output to two decimal places. A sample output follows. Allison Nields Gross Amount: $3575.00 Federal Tax: $536.25 State Tax: $125.13 Social Security Tax: $205.56 Medicare/Medicaid Tax: $98.31 Pension Plan: $178.75 Health Insurance: $75.00 Net Pay: $2356.00 This is what i have so far import java.io.*; import java.util.*; import javax.swing.JOptionPane; public class Lab1 { public static void main(String[] args) throws FileNotFoundException { String firstName; String lastName; String inputStr; String outputStr; double hoursWorked; double payRate; double grossAmount; double fincomeTax; double stateTax; double ssecurityTax; double mmediTax; double pPlan; double healthIns; double netPay; firstName = JOptionPane.showInputDialog ("Enter employees' first Name"); lastName = JOptionPane.showInputDialog ("Enter employees' last name"); inputStr = JOptionPane.showInputDialog ("Enter the hours worked by employee"); hoursWorked = Double.parseDouble (inputStr); inputStr = JOptionPane.showInputDialog ("Enter the employees' pay rate"); payRate = Double.parseDouble (inputStr); grossAmount = hoursWorked*payRate; fincomeTax = grossAmount*(.15); stateTax = grossAmount*( .035); ssecurityTax = grossAmount*(.0575); mmediTax = grossAmount*(.0275); pPlan = grossAmount*(.05); healthIns = grossAmount-75; netPay = grossAmount-fincomeTax-stateTax-ssecurit… // display results outputStr = "Employees Name: " + firstName + lastName +" " + "Gross Amount: $" + String.format("%.2f", grossAmount) + " " + "Federal Tax: $" + String.format("%.2f", fincomeTax) + " " + "State Tax: $" + String.format("%.2f", stateTax) + " " + "Social Security Tax: $" + String.format("%.2f", ssecurityTax) + " " + "Medicare/Medicaid Tax: $" + String.format("%.2f", mmediTax) + " " + "Pension plan: $" + String.format("%.2f", pPlan) + " " + "Health Insurance: $" + String.format("%.2f", healthIns) + " " + "Net Pay: $" + String.format("%.2f", netPay); PrintWriter outFile = new PrintWriter("employeeinfo.out"); outFile.printf("Employees Name: " + firstName + lastName); outFile.printf("Gross Amount: %.2f %n", grossAmount); outFile.printf("Federal Tax: %.2f %n", fincomeTax); outFile.printf("State Tax: %.2f %n", stateTax); outFile.printf("Social Security Tax: %.2f %n", ssecurityTax); outFile.printf("Medicare/Medicaid Tax: %.2f %n", mmediTax); outFile.printf("Pension Plan: %.2f %n", pPlan); outFile.printf("Health Insurance: %.2f %n",healthIns); outFile.printf("Net Pay: %.2f %n", netPay); outFile.close(); //outfile close }//class close }//static void main close JOptionPane.showMessageDialog(null, outputStr, "Employee Pay Data", JOptionPane.INFORMATION_MESSAGE); System.exit(0); } } Problem is i want a dialog box to show and it is not