GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 05-Mar-2009, 01:15
disk97 disk97 is offline
New Member
 
Join Date: Mar 2009
Posts: 13
disk97 has a little shameless behaviour in the past
Smile

Error E2314 Assign5.cpp 28: Call of nonfunction in function main()


Create a program that calculates the earnings and taxes for workers. The program will have:

a)The main program will read in lines from the terminal, which will prompt the user for this information for each worker:
Hourly Salary Hours Exemptions

b) The salary will be an hourly salary, and the hours will be the number of hours worked in a week. Your program should include a function for computing the pay for a week. If a person worked at most 40 hours, the pay is the hourly rate times the number of hours. If a person worked more than 40 hours, the pay for the first 40 hours is the regular hourly age, and the pay for overtime, the number of hours worked beyond 40, is 1.5 times the regular hourly wage for that worker. Thus the hourly salary and the number of hours will be arguments of this function.

c) Your program should include a second function for computing how much is withheld each week. The pay withheld is 20% of the weekly salary, minus $100 times the number of exemptions, over $600. Examples: if the weekly salary is $750, a worker with 1 exemption pays . A worker with the same salary and 2 exemptions has nothing withheld because
. Thus the salary and the number of exemptions (an integer) will be arguments of this function.

d)The number of workers will not be given beforehand, so use a while loop that will compute the pay until the user does not type in ‘y’ in response to the question: “Are there any more employees?” Keep track of the number of employees with a counter variable.

e)Your output file should consist of a sequence of lines of the form “The salary is $ ####.## and the pay withheld is $ ###.## ”, where the numbers are the pay and the amount withheld for the week. The end of the output file should consist of a line stating the number of employees. You will need the lines #include<iomanip> and cout << fixed << setprecision(2) for this.
----------------------------------------------------------------------
my code is below
I can not find what is wrong.

CPP / C++ / C Code:
#include<iostream>
#include<iomanip>
using namespace std;

double T_salary(double s, int h);
double T_exemption(double T_salary, int e);
						 //function declaration,
						//h=hours, s=hourly salary, e=exemptions
main()
{
	int h,e,count;
	double s,T_salary, T_exemption;
	count=0;
	cout<< fixed <<setprecision(2);    // 2 decimal places
	char flag = 'y';
	while(flag == 'y' || flag == 'Y')
	{
		cout<< "type in your Hourly salary $: ";
		cin>>s;
		cout<< "type in your work Hour a week: ";
		cin>>h;
		cout<< "type in number of Exemptions: ";
		cin >>e;
		cout<< "your weekly salary is $";
		cout<< T_salary(s,h);
		cout<< "your weekly the pay withheld is $";
		cout<< T_exemption(T_salary,e);
		cout<<"Are there any more employees?\n";
		cout<<"Type 'y' for yes, anything ";
		cout<<" else for no. \n";
		cin>>flag;
		count++;
	 }
	 cout <<"you computed" << count << "employees.";
}
double T_salary(double s, int h); //function definition
	if (h > 40)
	{
	return h*s+(h-40)*1.5*s;
	}
	else
	{
	return h*s;
	}

double T_exemption(double T_salary, int e); //function definition
	if (T_salary>=600)
	{
	return 0.20*(T_salary-600-100*e);
	}
	else
	{
	return 0;
	}

error shown

Error E2314 Assign5.cpp 28: Call of nonfunction in function main()
Error E2314 Assign5.cpp 30: Call of nonfunction in function main()
Error E2040 Assign5.cpp 40: Declaration terminated incorrectly
Error E2040 Assign5.cpp 50: Declaration terminated incorrectly
Last edited by LuciWiz : 05-Mar-2009 at 04:13. Reason: Please insert your C++ between [cpp] & ]/cpp] tags
  #2  
Old 05-Mar-2009, 06:31
Kimmo Kimmo is offline
Member
 
Join Date: Mar 2007
Location: Finland
Posts: 285
Kimmo is a jewel in the roughKimmo is a jewel in the roughKimmo is a jewel in the rough

Re: Can anyone help me this code?


My C++ is pretty rusty but this looks like a simple enough problem. Ignoring the requirements for your program, let's go through your code and see what's wrong with it (so you can have it compile at least).

Quote:
Error E2314 Assign5.cpp 28: Call of nonfunction in function main()
Error E2314 Assign5.cpp 30: Call of nonfunction in function main()
Error E2040 Assign5.cpp 40: Declaration terminated incorrectly
Error E2040 Assign5.cpp 50: Declaration terminated incorrectly
So, it says you're trying to use as a function something that is not a function. So... Maybe T_salary and T_exemption are not functions? Perhaps they're doubles? You have a line

CPP / C++ / C Code:
double s,T_salary, T_exemption;
in your main(). So, T_salary and T_exemption are doubles, not functions at all.

When you define/declare functions in the global namespace, you don't have to try to tell your main() function that they are functions returning doubles. You already said it once in

CPP / C++ / C Code:
double T_salary(double s, int h);
double T_exemption(double T_salary, int e);
Everyone knows about those functions now.

So, let's reduce the line to
CPP / C++ / C Code:
double s;
Now the compiler will see T_salary is a function. Before going on let's try to recompile.

The first error I get with my g++ 3.4.2 is
"
main.cpp: In function `int main()':
main.cpp:27: error: cannot convert `double (*)(double, int)' to `double' for arg
ument `1' to `double T_exemption(double, int)'
"

So let's see. The line looks like this:
CPP / C++ / C Code:
cout<< T_exemption(T_salary,e);
And you got to admit it, the compiler is right again. T_salary now is a function. So let's replace T_salary with a double value, which the function expects as an argument. Apparently s is the correct variable. So we replace like so:
CPP / C++ / C Code:
cout<< T_exemption(s,e);

Let's try to compile again. This time I get
"
main.cpp:37: error: expected unqualified-id before "if"
main.cpp:37: error: expected `,' or `;' before "if"
main.cpp:41: error: expected unqualified-id before "else"
main.cpp:41: error: expected `,' or `;' before "else"
main.cpp:47: error: expected unqualified-id before "if"
main.cpp:47: error: expected `,' or `;' before "if"
main.cpp:51: error: expected unqualified-id before "else"
main.cpp:51: error: expected `,' or `;' before "else"
"

I think basically it's saying it's pretty unexpected to see an if-else construct in the middle of nowhere.

So let's see. You have
CPP / C++ / C Code:
double T_salary(double s, int h); //function definition
	if (h > 40)
	{
	return h*s+(h-40)*1.5*s;
	}
	else
	{
	return h*s;
	}
Your comment says definition, but it's actually not.
CPP / C++ / C Code:
double T_salary(double s, int h); // declaration
double T_salary(double s, int h) // definition
{
}
So let's replace your definitions with
CPP / C++ / C Code:
double T_salary(double s, int h) //function definition
{
    if (h > 40)
	{
	return h*s+(h-40)*1.5*s;
	}
	else
	{
	return h*s;
	}
}
    
double T_exemption(double T_salary, int e) //function definition
{
    if (T_salary>=600)
	{
	return 0.20*(T_salary-600-100*e);
	}
	else
	{
	return 0;
	}
}
Now, let's try to compile. Compiles fine this time.

Output:
Code:
type in your Hourly salary $: 7 type in your work Hour a week: 40 type in number of Exemptions: 0 your weekly salary is $280.00your weekly the pay withheld is $0.00Are there any more employees? Type 'y' for yes, anything else for no. n you computed1employees.

Note that this has nothing to do with the requirements of your program, just getting it to compile.

You could also pay attention to your naming to make the code more readable. Compare
CPP / C++ / C Code:
int h,e,count;
	double s;
with
CPP / C++ / C Code:
int hours, exemptions, employerCount;
double salary;

Or compare functions
CPP / C++ / C Code:
double aa(double, int);
double Aa(double, int);
double aA(double, int);
with
CPP / C++ / C Code:
double calculateWeeklySalary(double, int);
double calculateMonthlySalary(double, int);
double calculateYearlySalary(double, int);
Descriptive naming is like documentation in itself.
  #3  
Old 05-Mar-2009, 10:58
disk97 disk97 is offline
New Member
 
Join Date: Mar 2009
Posts: 13
disk97 has a little shameless behaviour in the past

Re: Can anyone help me this code?


Thank you very much Kimmo !!!!!!!!!!
I love you it's very helpful.
 
 

Recent GIDBlogAccepted for Ph.D. program by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Trouble integrating console code into GUI Barman007 Java Forum 18 15-May-2008 14:05
How to sort random access file? wmmccoy0910 C Programming Language 12 04-Sep-2006 04:40
Here it is again! 35% - 40% off For Life! my-e-space Web Hosting Advertisements & Offers 0 20-Apr-2006 15:48
Guidelines for posting requests for help - UPDATED! WaltP C Programming Language 0 21-Apr-2005 03:44

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 21:26.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.