C++ Format issue

Joined
Dec 21, 2008
Messages
1
Reaction score
0
I wrote this code for a homework assignment, and I cant get the format of the Salary to output correctly, please tell me whats wrong. Heres the output:


Employee Payroll Report
******************************************************************************************************************
Name Rate Hours Overtime Hours Overtime Pay Total Pay
*********************************************************
joe 20 20 0 -1.07374e+008 -1.07374e+008
ted 20 50 10 -1.07374e+008 -1.07373e+008


Heres the code:



#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;
ofstream display("Employee.txt");
//******************************//
class Employee
{
private:

string name;
float payrate;
float hours;
float overtime;
float regpay;
float overtimepay;
float totalpay;

public:

//******************************//
void getinfo()
{
cout<<"Enter the employees name"<<endl;
cin>>name;
cout<<"Enter the hours worked"<<endl;
cin>>hours;
cout<<"Enter the hourly rate"<<endl;
cin>>payrate;
}
//******************************//
void reg()
{
if (hours<=40)
regpay=hours*payrate;
else
regpay=payrate*40;
}
//******************************//
void overtimecalc( )
{
float overtimehours=0;
float overtimepay=0;
if(hours>40)
{overtimehours=hours-40;
overtimepay = overtimehours*1.5*payrate;
}
}
//******************************//
void ohours()
{
if (hours>40)
overtime=hours-40;
else
overtime=0;
}
//******************************//
void total()
{
totalpay=regpay+overtimepay;
}
//******************************//
void header()
{
display << setw(15) <<"Employee Payroll Report";
display <<endl;
display <<"*********************************************************";
display <<"*********************************************************";
display <<endl;
display <<"Name "<<setw(10)<<" Rate "<<setw(10)<<" Hours "<<setw(15)<<" Overtime Hours "<<setw(15)<<" Overtime Pay "<<setw(15)<<" Total Pay";
display <<endl;
display <<"*********************************************************";
display <<endl;
}
void results()
{
display<<name<<setw(10)<<payrate<<setw(10)<<hours<<setw(15)<<overtime<<setw(15)<<overtimepay<<setw(15)<<totalpay;
display<<endl;
}
//******************************//
~Employee()
{
display<<"*********************************************************";
display<<endl;
}
};
//******************************//

int main()
{
char ch;
Employee emp;
emp.header();
do
{
emp.getinfo();
emp.reg();
emp.overtimecalc();
emp.ohours();
emp.total();
emp.results();
cout<<"Another employee? (y/n) : ";
cin>>ch;
cout<<endl;
}
while(ch != 'n' );
return 0;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top