Stuckincode's Profile
Reputation: 0
Apprentice
- Group:
- New Members
- Active Posts:
- 8 (0.04 per day)
- Joined:
- 05-October 12
- Profile Views:
- 132
- Last Active:
Oct 07 2012 06:55 PM- Currently:
- Offline
Previous Fields
- Dream Kudos:
- 0
Posts I've Made
-
In Topic: How do I properly use a file for input and create an output
Posted 7 Oct 2012
Ok, I figured it out, I just needed to add - overtime on lines 62 and 86.
Hope i'm not posting the code too many times, but this is my final coding before proper comments are added.
#include <iomanip> #include <iostream> #include <ctime> #include <fstream> #include <string> using namespace std; int main() { // Define Constants const double FICAPERCENTAGE = 0.0765; const double FEDERALTAX = 0.1500; const double INCOMETAX = 0.0300; // Define Variables int employeeNumber; double hourlyRate; int hoursWorked; int overtime; double overtimePay; double grossPay; // Dispays time and date function time_t sysTime; time (&sysTime); // Read data ifstream input("program3input.txt"); employeeNumber; hoursWorked; hourlyRate; input >> employeeNumber >> hoursWorked >> hourlyRate; input.close(); //Calculate gross and net pay overtime = hoursWorked - 40; overtimePay = hourlyRate * 1.5; grossPay = (hoursWorked - overtime) * hourlyRate + overtime * overtimePay; double ficaDeduction = grossPay * FICAPERCENTAGE; double federalTax = grossPay * FEDERALTAX; double incomeTax = grossPay * INCOMETAX; double netPay = grossPay - ficaDeduction - federalTax - incomeTax; double totalDeduction = ficaDeduction + federalTax + incomeTax; cout << fixed << setprecision(2); // Sets output at 2 decimal places cout << endl; cout << "Joe's Hardware Payroll Program" << setw(5) << endl; cout << "The current local date/time: " <<ctime(&sysTime); cout << "---------------------------------------------------------" << endl; cout << "Employee Number: " << setw(10) << employeeNumber << endl << endl; cout << "Hourly rate of pay: $ " << setw(6) << hourlyRate << endl; cout << "Regular Hours worked: " << setw(10) << hoursWorked - overtime << endl; cout << "Overtime Hours Worked: " << setw(10) << overtime << endl; cout << "Total Gross Pay: $ " << setw(4) << grossPay << endl; cout << "Deductions: " << setw(14) << endl; cout << "FICA: $ " << setw(8) << ficaDeduction << endl; cout << "Federal Tax: $ " << setw(8) << federalTax << endl; cout << "Income Tax: $ " << setw(8) << incomeTax << endl; cout << "---------------------------------------------------------" << endl; cout << "Total Deductions: $ " << setw(8) << totalDeduction << endl; cout << " ======" << endl; cout << "Net Pay: $ " << setw(6) << netPay << endl; cout << "---------------------------------------------------------" << endl; // Output data ofstream output; output.open ("program3output.txt"); // Edits lines of code output << fixed << setprecision(2); output << endl; output << "Joe's Hardware Payroll Program" << setw(5) << endl; output << "The current local date/time: " <<ctime(&sysTime); output << "---------------------------------------------------------" << endl; output << "Employee Number: " << setw(10) << employeeNumber << endl << endl; output << "Hourly rate of pay: $ " << setw(6) << hourlyRate << endl; output << "Regular Hours worked: " << setw(10) << hoursWorked - overtime << endl; output << "Overtime Hours Worked: " << setw(10) << overtime << endl; output << "Total Gross Pay: $ " << setw(4) << grossPay << endl; output << "Deductions: " << setw(14) << endl; output << "FICA: $ " << setw(8) << ficaDeduction << endl; output << "Federal Tax: $ " << setw(8) << federalTax << endl; output << "Income Tax: $ " << setw(8) << incomeTax << endl; output << "---------------------------------------------------------" << endl; output << "Total Deductions: $ " << setw(8) << totalDeduction << endl; output << " ======" << endl; output << "Net Pay: $ " << setw(6) << netPay << endl; output << "---------------------------------------------------------" << endl; output.close(); return 0; } -
In Topic: How do I properly use a file for input and create an output
Posted 7 Oct 2012
I got it working with proper output, thank you all, the code I had to fix
overtime = hoursWorked - 40; overtimePay = hourlyRate * 1.5; grossPay = (hoursWorked - overtime) * hourlyRate + overtime * overtimePay; double ficaDeduction = grossPay * FICAPERCENTAGE; double federalTax = grossPay * FEDERALTAX; double incomeTax = grossPay * INCOMETAX; double netPay = grossPay - ficaDeduction - federalTax - incomeTax; double totalDeduction = ficaDeduction + federalTax + incomeTax;
Joe's Hardware Payroll Program
The current local date/time: Sun Oct 07 18:02:12 2012
---------------------------------------------------------
Employee Number: 21
Hourly rate of pay: $ 9.20
Regular Hours worked: 45
Overtime Hours Worked: 5
Total Gross Pay: $ 437.00
Deductions:
FICA: $ 33.43
Federal Tax: $ 65.55
Income Tax: $ 13.11
---------------------------------------------------------
Total Deductions: $ 112.09
======
Net Pay: $ 324.91
---------------------------------------------------------
I spoke too soon, I see I have 45 regular hours and 5 hours of overtime when anything over 40 is considered overtime, any suggestions? -
In Topic: How do I properly use a file for input and create an output
Posted 7 Oct 2012
I realized that I needed to delete line 40 to get rid of the numbers jumbled together on output. Do I have to create an Else If statement to get my overtime and regular pay to calculate correctly? -
In Topic: How do I properly use a file for input and create an output
Posted 7 Oct 2012
jdavi134, on 07 October 2012 - 02:42 PM, said:For your overtimePay error. Look at lines 46 & 48. Pretty clear answer.
Happy Coding
EDIT: was looking at original post.
Thank you!!!! Thank you!!!! It is working, now I just have to make sure the math is right, you are a genius! I wish I could ship you a beer lol.
Only issue now is the output isn't correct
, I am almost done though, thank you everyone for your help.
21459.2
Joe's Hardware Payroll Program
The current local date/time: Sun Oct 07 16:56:11 2012
---------------------------------------------------------
Employee Number: 21
Hourly rate of pay: $ 9.20
Regular Hours worked: 45
Overtime Hours Worked: 5.00
Total Gross Pay: $ 483.00
Deductions:
FICA: $ 36.95
Federal Tax: $ 72.45
---------------------------------------------------------
Total Deductions: $ 123.89
======
Net Pay: $ 359.11
---------------------------------------------------------
Press any key to continue . . . -
In Topic: How do I properly use a file for input and create an output
Posted 7 Oct 2012
Thank you, that did help and I now I am getting the numbers I entered into the program3input.txt file on the command line. 21459.2 is displaying but what is typed in the file is one line 21 45 9.2 . which is supposed to be ID, hours, and hourly. I am just somehow not getting the calculations or editing, I am also getting a run time check error #3 the variable 'overtimePay' is being used without being initialized. I thought I had declared and initialized all of my variables. Any help is definitely appreciated, as I have googled this issue, and when I followed the instructions in my book I wasn't getting any output to the command line.
#include <iomanip>
#include <iostream>
#include <ctime>
#include <fstream>
#include <string>
using namespace std;
int main()
{
// Define Constants
const double FICAPERCENTAGE = 0.0765;
const double FEDERALTAX = 0.1500;
const double INCOMETAX = 0.0300;
// Define Variables
int employeeNumber;
double hourlyRate;
int hoursWorked;
double overtime;
double overtimePay;
double grossPay;
// Dispays time and date function
time_t sysTime;
time (&sysTime);
// Read data
ifstream input("program3input.txt");
employeeNumber;
hoursWorked;
hourlyRate;
input >> employeeNumber >> hoursWorked >> hourlyRate;
cout << employeeNumber << hoursWorked << hourlyRate;
input.close();
//Calculate gross and net pay
grossPay = hoursWorked * hourlyRate + overtimePay;
overtime = hoursWorked - 40;
overtimePay = overtime * (hourlyRate * 1.5);
double ficaDeduction = grossPay * FICAPERCENTAGE;
double federalTax = grossPay * FEDERALTAX;
double incomeTax = grossPay * INCOMETAX;
double netPay = grossPay - ficaDeduction - federalTax - incomeTax;
double totalDeduction = ficaDeduction + federalTax + incomeTax;
cout << fixed << setprecision(2); // Sets output at 2 decimal places
cout << endl;
cout << "Joe's Hardware Payroll Program" << setw(5) << endl;
cout << "The current local date/time: " <<ctime(&sysTime);
cout << "---------------------------------------------------------" << endl;
cout << "Employee Number: " << setw(10) << employeeNumber << endl << endl;
cout << "Hourly rate of pay: $ " << setw(6) << hourlyRate << endl;
cout << "Regular Hours worked: " << setw(10) << hoursWorked << endl;
cout << "Overtime Hours Worked: " << setw(10) << overtime << endl;
cout << "Total Gross Pay: $ " << setw(4) << grossPay << endl;
cout << "Deductions: " << setw(14) << endl;
cout << "FICA: $ " << setw(8) << ficaDeduction << endl;
cout << "Federal Tax: $ " << setw(8) << federalTax << endl;
cout << "---------------------------------------------------------" << endl;
cout << "Total Deductions: $ " << setw(8) << totalDeduction << endl;
cout << " ======" << endl;
cout << "Net Pay: $ " << setw(6) << netPay << endl;
cout << "---------------------------------------------------------" << endl;
// Output data
ofstream fout;
fout.open ("program3output.txt");
// Edits lines of code
fout << fixed << setprecision(2);
fout << endl;
fout << "Joe's Hardware Payroll Program" << setw(5) << endl;
fout << "The current local date/time: " <<ctime(&sysTime);
fout << "---------------------------------------------------------" << endl;
fout << "Employee Number: " << setw(10) << employeeNumber << endl << endl;
fout << "Hourly rate of pay: $ " << setw(6) << hourlyRate << endl;
fout << "Regular Hours worked: " << setw(10) << hoursWorked << endl;
fout << "Overtime Hours Worked: " << setw(10) << overtime << endl;
fout << "Total Gross Pay: $ " << setw(4) << grossPay << endl;
fout << "Deductions: " << setw(14) << endl;
fout << "FICA: $ " << setw(8) << ficaDeduction << endl;
fout << "Federal Tax: $ " << setw(8) << federalTax << endl;
fout << "---------------------------------------------------------" << endl;
fout << "Total Deductions: $ " << setw(8) << totalDeduction << endl;
fout << " ======" << endl;
fout << "Net Pay: $ " << setw(6) << netPay << endl;
fout << "---------------------------------------------------------" << endl;
fout.close();
return 0;
}
Sorry, let me try putting that code in again.
#include <iomanip> #include <iostream> #include <ctime> #include <fstream> #include <string> using namespace std; int main() { // Define Constants const double FICAPERCENTAGE = 0.0765; const double FEDERALTAX = 0.1500; const double INCOMETAX = 0.0300; // Define Variables int employeeNumber; double hourlyRate; int hoursWorked; double overtime; double overtimePay; double grossPay; // Dispays time and date function time_t sysTime; time (&sysTime); // Read data ifstream input("program3input.txt"); employeeNumber; hoursWorked; hourlyRate; input >> employeeNumber >> hoursWorked >> hourlyRate; cout << employeeNumber << hoursWorked << hourlyRate; input.close(); //Calculate gross and net pay grossPay = hoursWorked * hourlyRate + overtimePay; overtime = hoursWorked - 40; overtimePay = overtime * (hourlyRate * 1.5); double ficaDeduction = grossPay * FICAPERCENTAGE; double federalTax = grossPay * FEDERALTAX; double incomeTax = grossPay * INCOMETAX; double netPay = grossPay - ficaDeduction - federalTax - incomeTax; double totalDeduction = ficaDeduction + federalTax + incomeTax; cout << fixed << setprecision(2); // Sets output at 2 decimal places cout << endl; cout << "Joe's Hardware Payroll Program" << setw(5) << endl; cout << "The current local date/time: " <<ctime(&sysTime); cout << "---------------------------------------------------------" << endl; cout << "Employee Number: " << setw(10) << employeeNumber << endl << endl; cout << "Hourly rate of pay: $ " << setw(6) << hourlyRate << endl; cout << "Regular Hours worked: " << setw(10) << hoursWorked << endl; cout << "Overtime Hours Worked: " << setw(10) << overtime << endl; cout << "Total Gross Pay: $ " << setw(4) << grossPay << endl; cout << "Deductions: " << setw(14) << endl; cout << "FICA: $ " << setw(8) << ficaDeduction << endl; cout << "Federal Tax: $ " << setw(8) << federalTax << endl; cout << "---------------------------------------------------------" << endl; cout << "Total Deductions: $ " << setw(8) << totalDeduction << endl; cout << " ======" << endl; cout << "Net Pay: $ " << setw(6) << netPay << endl; cout << "---------------------------------------------------------" << endl; // Output data ofstream fout; fout.open ("program3output.txt"); // Edits lines of code fout << fixed << setprecision(2); fout << endl; fout << "Joe's Hardware Payroll Program" << setw(5) << endl; fout << "The current local date/time: " <<ctime(&sysTime); fout << "---------------------------------------------------------" << endl; fout << "Employee Number: " << setw(10) << employeeNumber << endl << endl; fout << "Hourly rate of pay: $ " << setw(6) << hourlyRate << endl; fout << "Regular Hours worked: " << setw(10) << hoursWorked << endl; fout << "Overtime Hours Worked: " << setw(10) << overtime << endl; fout << "Total Gross Pay: $ " << setw(4) << grossPay << endl; fout << "Deductions: " << setw(14) << endl; fout << "FICA: $ " << setw(8) << ficaDeduction << endl; fout << "Federal Tax: $ " << setw(8) << federalTax << endl; fout << "---------------------------------------------------------" << endl; fout << "Total Deductions: $ " << setw(8) << totalDeduction << endl; fout << " ======" << endl; fout << "Net Pay: $ " << setw(6) << netPay << endl; fout << "---------------------------------------------------------" << endl; fout.close(); return 0; }
My Information
- Member Title:
- New D.I.C Head
- Age:
- Age Unknown
- Birthday:
- Birthday Unknown
- Gender:
Contact Information
- E-mail:
- Click here to e-mail me
Friends
Stuckincode hasn't added any friends yet.
|
|


Find Topics
Find Posts
View Reputation Given
|
Comments
Stuckincode has no profile comments yet. Why not say hello?