calculate program for payroll problem c++

my program has errors i can't find/fix

Page 1 of 1

4 Replies - 10473 Views - Last Post: 23 April 2007 - 09:48 PM Rate Topic: -----

#1 skp1985   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 23-April 07

calculate program for payroll problem c++

Posted 23 April 2007 - 02:11 PM

[size=7]Hi i am trying to figure out how to fix this. I have to use info from a data file . input file format:name, hours, pay rate. from this i have to calculate the salary for each employee and calculate the tax and calculate the average gross salary of all employees in the list. hours and pay rate must be > 0

if salary < 3500 then tax = 0
if salary is between 3500-8000 then tax is 6% of amount over 3500 + $105
if salary is between 8000-20000 then tax is 11% of amount over 8000 + $375
if salary is between 20000-34000 then tax is 17% of amount over 20000 + $1695
if salary is between 34000-52000 then tax is 24% of amount over 34000 + $4075
if salary is over 52000 then tax is 32% of amount over 52000 + $8395

the program must print to output like so:ex:

this program will calculate the user's tax liabilities
========================================================
name hours pay rate salary tax
========================================================
fred rubbles 2256 12.75 28764.00 6584.88
donald duck *********hours invalid*************

HERE IS WHAT CODE IVE DONE BUT IT ISNT WORKING i've been working on this for weeks and the assignment is now almost due and i cannot fix it PLEASE help thank you!!!

#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
void main (void)
{
/*****Declare Variables*****/
	ifstream fin;
	ofstream fout;
	int hours, counter, num;
	float pay_rate, tax;
	double avg_sal, total_sal;
	string dataf_name, name, dataf_out;

	/**********Input***********/ 
cout<< "Enter input file name:";
getline(cin,dataf_name);
cout<< "Enter output file name:";
getline(cin,dataf_out);
//cin>>dataf_out;
fin.open (dataf_name.c_str());
if (fin.fail())
cout<< "Bad file name!";
else
{
	fout.open("out.txt");
	cout<<setprecision(2);
	fout<<setprecision(2);
	cout<<\t"This pogram will calculate and report user's tax liabilities."<<endl;
	cout<<\t"===================================================="<<endl;
	cout<<\t"Name"<<endl<<name;
	cout<<setw(10)<<"Hours"<<endl<<hours;
	cout<<setw(20)<<"Pay Rate"<<endl<<pay_rate;
	cout<<setw(30)<<"Salary"<<endl<<salary;
	cout<<setw(40)<<"Tax"<<tax<<endl;
	cout<<\t"===================================================="<<endl;
	getline(fp, name);
	while (fp) // while (!fp.eof))
	{
		fin>>hours;
		fin>>pay_rate;
		if hours < 0 
			cout<<"Invalid hours";
		if pay_rate < 0
			cout<<"Invlaid pay rate";
		else
		salary = pay_rate * hours;
		if salary < 3500
		tax = 0;
else if salary < 8000
	tax = [((salary - 3500)*.06)+ 105];
else if salary < 20000
	tax = [((salary - 8000)*.11)+ 375];
else if salary < 34000
	tax = [((salary - 20000)*.17+ 1695];
else if salary < 52000
	tax = [((salary - 34000)*.24+ 4075];
else if salary > 52000
	tax = [((salary - 52000)*.32+ 8395];
infile>>name;
while(infile)
{
counter = 0;
sum = 0;
infile>>num;
while (infile)
{
	total_sal = total_sal + num;
	salary++;
	infile>> num;
}
avg_sal= total_sal/num;

/**********output********/
cout<<\t"Average Gross Salary:"\s\s<<avg_sal<<endl;
}




Is This A Good Question/Topic? 0
  • +

Replies To: calculate program for payroll problem c++

#2 skp1985   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 23-April 07

Re: calculate program for payroll problem c++

Posted 23 April 2007 - 08:01 PM

Hi i am trying to figure out how to fix this. I have to use info from a data file . the input file format is:name, hours, pay rate. from this i have to calculate the salary for each employee and calculate the tax and calculate the average gross salary of all employees in the list. hours and pay rate must be > 0. I PREVIOULSY POSTED ANOTHER VERSION OF THIS i worked on it and came up with a better working code. please help i do not know what these errors mean.

if salary < 3500 then tax = 0
if salary is between 3500-8000 then tax is 6% of amount over 3500 + $105
if salary is between 8000-20000 then tax is 11% of amount over 8000 + $375
if salary is between 20000-34000 then tax is 17% of amount over 20000 + $1695
if salary is between 34000-52000 then tax is 24% of amount over 34000 + $4075
if salary is over 52000 then tax is 32% of amount over 52000 + $8395

the program must print to output like so:

this program will calculate the user's tax liabilities
========================================================
name hours pay rate salary tax
========================================================
fred rubbles 2256 12.75 28764.00 6584.88
donald duck *********hours invalid*************

average gross salary is:


#include <fstream>
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
void main (void)
{
/*****Declare Variables*****/
	fstream fin;
	ofstream fout;
	int hours, counter, num;
	float pay_rate, tax;
	double avg_sal, total_sal, salary;
	string dataf_name, name, dataf_out;

	/**********Input***********/ 
cout<< "Enter input file name:";
getline(cin,dataf_name);
cout<< "Enter output file name:";
getline(cin,dataf_out);
//cin>>dataf_out;
fin.open (dataf_name.c_str());
if (fin.fail())
cout<< "Bad file name!";
else
{
	fout.open("out.txt");
	cout<<setprecision(2);
	fout<<setprecision(2);
	cout<<\t"This program will calculate and report user's tax liabilities."<<endl;
	cout<<\t"====================================================================="<<endl;
	cout<<\t"Name"<<endl<<name;
	cout<<setw(10)<<"Hours"<<endl<<hours;
	cout<<setw(20)<<"Pay Rate"<<endl<<pay_rate;
	cout<<setw(30)<<"Salary"<<endl<<salary;
	cout<<setw(40)<<"Tax"<<tax<<endl;
	cout<<\t"====================================================================="<<endl;
	getline(fp, name);
	while (fp) // while (!fp.eof))
	{
		fin>>hours;
		fin>>pay_rate;
		if (hours < 0 )
			cout<<"Invalid hours";
		if (pay_rate < 0)
			cout<<"Invlaid pay rate";
		else
		salary = pay_rate * hours;
		if (salary < 3500)
		tax = 0;
else if (salary <= 8000)
	float tax = ((salary - 3500)*.06)+ 105);
else if (salary <= 20000)
	float tax = ((salary - 8000)*.11)+ 375);
else if (salary <= 34000)
	float tax = ((salary - 20000)*.17+ 1695);
else if (salary <= 52000)
	float tax = ((salary - 34000)*.24+ 4075);
else  (salary > 52000)
	float tax = ((salary - 52000)*.32+ 8395);
 int count = 0;
		  while(!fp.eof())
		  {
		   count++;
		   infile>>name;
		   infile>>wage;
		   cout<<"Name: "<<name<<" Wages: "<<wage<<endl;
		   total = total + wage
		  

	avg_sal= total_sal/num;
	cout<<\t"Average Gross Salary:"\s\s<<avg_sal<<endl;
}




HERE ARE THE ERRORS!! MOST ARE THE SAME THING THERE ARE ONLY 5 UNIQUE ERRORS.


error C2017: illegal escape sequence
error C2065: 't' : undeclared identifier
syntax error : missing ';' before 'string'
error C2563: mismatch in formal parameter list
error C2568: '<<' : unable to resolve function overload
c:\program files\microsoft visual studio 8\vc\include\ostream(977): could be 'std::basic_ostream<_Elem,_Traits> &std::endl(std::basic_ostream<_Elem,_Traits> &)'
with
[
_Elem=wchar_t,
_Traits=std::char_traits<wchar_t>
]
c:\program files\microsoft visual studio 8\vc\include\ostream(969): or 'std::basic_ostream<_Elem,_Traits> &std::endl(std::basic_ostream<_Elem,_Traits> &)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\program files\microsoft visual studio 8\vc\include\ostream(943): or 'std::basic_ostream<_Elem,_Traits> &std::endl(std::basic_ostream<_Elem,_Traits> &)'
error C2017: illegal escape sequence
error C2143: syntax error : missing ';' before 'string'
error C2563: mismatch in formal parameter list
error C2568: '<<' : unable to resolve function overload
c:\program files\microsoft visual studio 8\vc\include\ostream(977): could be 'std::basic_ostream<_Elem,_Traits> &std::endl(std::basic_ostream<_Elem,_Traits> &)'
with
[
_Elem=wchar_t,
_Traits=std::char_traits<wchar_t>
]
c:\program files\microsoft visual studio 8\vc\include\ostream(969): or 'std::basic_ostream<_Elem,_Traits> &std::endl(std::basic_ostream<_Elem,_Traits> &)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\program files\microsoft visual studio 8\vc\include\ostream(943): or 'std::basic_ostream<_Elem,_Traits> &std::endl(std::basic_ostream<_Elem,_Traits> &)'
error C2017: illegal escape sequence
error C2143: syntax error : missing ';' before 'string'
error C2563: mismatch in formal parameter list
error C2568: '<<' : unable to resolve function overload
c:\program files\microsoft visual studio 8\vc\include\ostream(977): could be 'std::basic_ostream<_Elem,_Traits> &std::endl(std::basic_ostream<_Elem,_Traits> &)'
with
[
_Elem=wchar_t,
_Traits=std::char_traits<wchar_t>
]
c:\program files\microsoft visual studio 8\vc\include\ostream(969): or 'std::basic_ostream<_Elem,_Traits> &std::endl(std::basic_ostream<_Elem,_Traits> &)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\program files\microsoft visual studio 8\vc\include\ostream(943): or 'std::basic_ostream<_Elem,_Traits> &std::endl(std::basic_ostream<_Elem,_Traits> &)'
c:\users\anthony\documents\visual studio 2005\projects\project13\a\iiiiiii.cpp(104) : error C2017: illegal escape sequence
c:\users\anthony\documents\visual studio 2005\projects\project13\a\iiiiiii.cpp(104) : error C2143: syntax error : missing ';' before 'string'
c:\users\anthony\documents\visual studio 2005\projects\project13\a\iiiiiii.cpp(104) : error C2563: mismatch in formal parameter list
c:\users\anthony\documents\visual studio 2005\projects\project13\a\iiiiiii.cpp(104) : error C2568: '<<' : unable to resolve function overload
c:\program files\microsoft visual studio 8\vc\include\ostream(977): could be 'std::basic_ostream<_Elem,_Traits> &std::endl(std::basic_ostream<_Elem,_Traits> &)'
with
[
_Elem=wchar_t,
_Traits=std::char_traits<wchar_t>
]
c:\program files\microsoft visual studio 8\vc\include\ostream(969): or 'std::basic_ostream<_Elem,_Traits> &std::endl(std::basic_ostream<_Elem,_Traits> &)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\program files\microsoft visual studio 8\vc\include\ostream(943): or 'std::basic_ostream<_Elem,_Traits> &std::endl(std::basic_ostream<_Elem,_Traits> &)'
error C2065: 'fp' : undeclared identifier
error C2059: syntax error : ')'
warning C4244: 'initializing' : conversion from 'double' to 'float', possible loss of data
error C2059: syntax error : ')'
warning C4244: 'initializing' : conversion from 'double' to 'float', possible loss of data
warning C4244: 'initializing' : conversion from 'double' to 'float', possible loss of data
warning C4244: 'initializing' : conversion from 'double' to 'float', possible loss of data
error C2144: syntax error : 'float' should be preceded by ';'
warning C4244: 'initializing' : conversion from 'double' to 'float', possible loss of data
error C2228: left of '.eof' must have class/struct/union
type is ''unknown-type''
c:\users\anthony\documents\visual studio 2005\projects\project13\a\iiiiiii.cpp(129) : fatal error C1903: unable to recover from previous error(s); stopping compilation[/color]
Was This Post Helpful? 0
  • +
  • -

#3 NickDMax   User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2255
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: calculate program for payroll problem c++

Posted 23 April 2007 - 08:13 PM

problem #1. error C2017: illegal escape sequence

To use excepe sequances like "\t" or "\n" or even"\a" you need to enclose them in quotes.
cout << '\t' << "This is tabbed over\nThis is on a new line";

so you have a lot of lines that look like:
cout<<\t"Name"<<endl<<name; which SHOULD look like:
cout<<"\tName"<<endl<<name;

and "\s" is not an escape sequence...

#2 you have undeclared identifiers: "salary", "fp", "infile", "sum". Even if they WERE decalred you use them before they are initialized, the same with "name", "hours", "pay_rate", "tax", and probably others.
(I assume that "fp" is supposed to be "fin").

#3 You use brackets [ ] like they are ( ) which works in math, but not in C++. The brackets are actually an operator, and since you didn't overload the operator with a new behavior this will not work. Basicly just get rid of them.

#4 you don't use the correct syntax for an "if-statment" The syntax should be:
if (condition) { do something }
or at the VERY LEAST:
if (condition) statement;
but recomend that you always use the brackets as it will greatly help prevent logic errors.

#5 you were missing various }'s and )'s

Here is you code so that it will compile. It DOES NOT do what you want it to do. I just fixed the syntax errors.
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>

using namespace std;

int main (void)
{
	//*****Declare Variables*****
	ifstream fin;
	ofstream fout;
	int hours=0, counter, num, sum;
	float pay_rate=0, tax=0, salary=0;
	double avg_sal, total_sal;
	string dataf_name, name, dataf_out;

	//**********Input***********
	cout<< "Enter input file name:";
	getline(cin,dataf_name);
	cout<< "Enter output file name:";
	getline(cin,dataf_out);
	//cin>>dataf_out;
	fin.open (dataf_name.c_str());
	if (fin.fail())
	{
	cout<< "Bad file name!";
	}
	else
	{
		fout.open("out.txt");
		cout<<setprecision(2);
		fout<<setprecision(2);
		cout<<"\tThis pogram will calculate and report user's tax liabilities."<<endl;
		cout<<"\t===================================================="<<endl;
		cout<<"\tName"<<endl<<name;
		cout<<setw(10)<<"Hours"<<endl<<hours;
		cout<<setw(20)<<"Pay Rate"<<endl<<pay_rate;
		cout<<setw(30)<<"Salary"<<endl<<salary;
		cout<<setw(40)<<"Tax"<<tax<<endl;
		cout<<"\t===================================================="<<endl;
		getline(fin, name);
		while (fin) // while (!fp.eof))
		{
			fin>>hours;
			fin>>pay_rate;
			if (hours < 0)
			{
				cout<<"Invalid hours";
			}
			if (pay_rate < 0)
			{
				cout<<"Invlaid pay rate";
			} else
			{
				salary = pay_rate * hours;
			}
			if (salary < 3500)
			{
				tax = 0;
			} else if (salary < 8000)
			{
				tax = ((salary - 3500)*.06)+ 105;
			} else if (salary < 20000)
			{
				tax = ((salary - 8000)*.11)+ 375;
			} else if (salary < 34000)
			{
				tax = ((salary - 20000)*.17)+ 1695;
			} else if (salary < 52000)
			{
				tax = ((salary - 34000)*.24)+ 4075;
			} else if (salary > 52000)
			{
				tax = ((salary - 52000)*.32)+ 8395;
			}
			fin>>name;
			while(fin)
			{
				counter = 0;
				sum = 0;
				fin>>num;
				while (fin)
				{
					total_sal = total_sal + num;
					salary++;
					fin>> num;
				}
				avg_sal= total_sal/num;

				/**********output********/
				cout<<"\tAverage Gross Salary:  "<<avg_sal<<endl;
			}
		}
	}
	return 0;
}

Was This Post Helpful? 0
  • +
  • -

#4 NickDMax   User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2255
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: calculate program for payroll problem c++

Posted 23 April 2007 - 08:44 PM

Topics Merged... please do not double post.
Was This Post Helpful? 0
  • +
  • -

#5 skp1985   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 23-April 07

Re: calculate program for payroll problem c++

Posted 23 April 2007 - 09:48 PM

thanks so much. i went and fixed one of the errors with initializing the total_sal. now my only problem is trying to figure why it keeps telling me im converting a double to a float. i will go figure this out now thanks again!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1