I'm currently learning C++ and got my code to do everything I want it to but it seems as if the code is not very efficient because I basically doubled the code from my output console so it shows up in a text file. If you can, could you explain what I am doing wrong and what would you suggest I do in order to make the code more efficient. (Also column one needs to be left justify and column two has to be right justify in both console and text file which I believe I did correctly.)
/* Description: This program calculates and prints the monthly paycheck for an employee (Output in command prompt and .txt file).*/
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
using namespace std;
char name[256];
double gross;
double fiTax;
double sTax;
double ssTax;
double mediTax;
double pPlan;
double hInsurance;
double tax;
double total;
int main() {
std::cout << "Please enter your name: ";
std::cin.getline(name, 256);
cout << "Please enter your gross amount: ";
cin >> gross;
std::cout << std::fixed;
std::cout << std::setprecision(2);
fiTax = gross * .15;
sTax = gross * .035;
ssTax = gross * .0575;
mediTax = gross * .0275;
pPlan = gross * .05;
hInsurance = 75;
tax = fiTax + sTax + ssTax + mediTax + pPlan + hInsurance;
total = gross - tax;
system("cls");
ofstream file;
file << std::fixed << std::setprecision(2);
file.open("report.txt");
cout << left<< setw(28) << name << endl;
file << left << setw(28) << name << endl;
cout << left << setw(28) << "Gross Amount: ............ $";
cout << right << setw(7) << gross << endl;
file << left << setw(28) << "Gross Amount: ............ $";
file << right << setw(7) << gross << endl;
cout << left << setw(28) << "Federal Tax: ............. $";
cout << right << setw(7) << fiTax << endl;
file << left << setw(28) << "Federal Tax: ............. $";
file << right << setw(7) << fiTax << endl;
cout << left << setw(28) << "State Tax: ............... $";
cout << right << setw(7) << sTax << endl;
file << left << setw(28) << "State Tax: ............... $";
file << right << setw(7) << sTax << endl;
cout << left << setw(28) << "Social Security Tax: ..... $";
cout << right << setw(7) << ssTax << endl;
file << left << setw(28) << "Social Security Tax: ..... $";
file << right << setw(7) << ssTax << endl;
cout << left << setw(28) << "Medicare/medicaid Tax: ... $";
cout << right << setw(7) << mediTax << endl;
file << left << setw(28) << "Medicare/medicaid Tax: ... $";
file << right << setw(7) << mediTax << endl;
cout << left << setw(28) << "Pension Plan: ............ $";
cout << right << setw(7) << pPlan << endl;
file << left << setw(28) << "Pension Plan: ............ $";
file << right << setw(7) << pPlan << endl;
cout << left << setw(28) << "Health Insurance: ........ $";
cout << right << setw(7) << hInsurance << endl;
file << left << setw(28) << "Health Insurance: ........ $";
file << right << setw(7) << hInsurance << endl;
cout << left << setw(28) << "Net Pay: ................. $";
cout << right << setw(7) << total << endl;
file << left << setw(28) << "Net Pay: ................. $";
file << right << setw(7) << total << endl;
file.close();
return 0;
}