hello, I am looking for some assistance in fixing a calculation string in my C++ code.
the issue that I am having is my monthly gross salary is not outputting correctly. I have created my inData.txt file with the following information:
Giselle Robinson Accounting
5600 5 30
450 9
75 1.5
my output should read:
Monthly Gross Salary : $ 5600.00, Monthly Bonus : 5.00%, Taxes : 30.00%
Paycheck : $4116.00
the incorrect output that i am getting is:
Monthly Gross Salary : $ 5880.00, Monthly Bonus : 5.00%, Taxes : 30.00%
Paycheck : $4116.00
I am almost positive that my issue is with my calculation for monthly salary and paycheck. can somebody assist me with fixing this please?
What I have tried:
everything else works and outputs exactly how it should be.
here is my code:
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
#include <cstdio>
using namespace std;
int main()
{
ifstream inFile("C:/Users/Student/Desktop/CS265 programming in C++/weekly assignments/week 2 assignment/week 2 assignment/week 2 assignment/inData.txt");
ofstream outFile("C:/Users/Student/Desktop/CS265 programming in C++/weekly assignments/week 2 assignment/week 2 assignment/week 2 assignment/outData.txt");
outFile.open("C:/Users/Student/Desktop/CS265 programming in C++/weekly assignments/week 2 assignment/week 2 assignment/week 2 assignment/outData.txt");
if (inFile.is_open())
{
cout << "File opened\n" << endl;
}
else
{
perror("File Failed to open");
return 1;
}
{
std::cout << std::fixed;
std::cout << std::setprecision(2);
}
string firstName,
lastName,
department;
double monthlySalary,
monthlyBonus,
taxes,
payCheck,
distanceTraveled,
travelingTime,
coffeeCost,
coffeeSales,
averageSpeed;
int cupsSold;
inFile >> firstName >> lastName >> department;
inFile >> monthlySalary >> monthlyBonus >> taxes;
inFile >> distanceTraveled >> travelingTime;
inFile >> cupsSold >> coffeeCost;
monthlySalary = monthlySalary + (monthlyBonus / 100 * monthlySalary);
payCheck = monthlySalary - (taxes / 100 * monthlySalary);
averageSpeed = distanceTraveled / travelingTime;
coffeeSales = cupsSold * coffeeCost;
outFile << "Name : " << firstName + ' ' + lastName << ", Department : " << department << endl;
outFile << "Monthly Gross Salary : $ " << monthlySalary << ", Monthly Bonus : " << monthlyBonus << "%, Taxes : " <<taxes << "%" << endl;
outFile << "Paycheck : $" << payCheck << endl;
outFile << "distance traveled : " << distanceTraveled << " miles" << ", traveling time: " << travelingTime << ", hours" << endl;
outFile << "Average Speed : " << averageSpeed << " mph" << endl;
outFile << "number of coffee cups sold: " << cupsSold << ", cost: $ " << coffeeCost << " per cup " << endl;
outFile << "Sales Amount : $" << coffeeSales << endl;
inFile.close();
outFile.close();
cout << "Name : " << firstName + ' ' + lastName << ", Department : " << department << endl;
cout << "Monthly Gross Salary : $ " << monthlySalary << ", Monthly Bonus : " << monthlyBonus << "%, Taxes : " <<taxes << "%" << endl;
cout << "Paycheck : $" << payCheck << endl;
cout << "distance traveled : " << distanceTraveled << " miles" << ", traveling time: " << travelingTime << ", hours" << endl;
cout << "Average Speed : " << averageSpeed << " mph" << endl;
cout << "number of coffee cups sold: " << cupsSold << ", cost: $ " << coffeeCost << " per cup " << endl;
cout << "Sales Amount : $" << coffeeSales << endl;
cin.get();
return 0;
}