I am trying to write a program that will demonstrate the use of functions with a structure. I know a lot of students try to get quick answers, I want to learn, but I am stuck, and could really use some help.

I keep getting the following error: C2448: 'salary' : function-style initializer appears to be a function definition

I am only trying to get one function to work in the menue (the 1st one) and then I will move on. Baby steps :) I have declared the function before my int main statement. The function definitions are just a simple input/output statement for hours and wage.

I just can't see where I am going wrong. Can someone point me in the right direction please. I have included the code below. I know it is pretty ugly. Bare with me, I am learning, and like I say this is a rough draft, just tring to get the menu functions to work. I think, hope I am close. I understand functions, but combining them with structures is messing me up. Do I use the void command when calling the function or would I use float instead since the variables are all floats. Sorry for all the questions. I really want to learn, anyh help is greatly appreciated.


Any help is greatly appreciated.

///////////////////////////////////////////////////////////////////////

#include <iomanip> 							// used for setprecison and ios flags
#include <iostream>
using namespace std;
#include "process.h"


// Structure                                           

struct pay
{
	float rop, hours;
	float wage, regularwage, noot;        //noot represents no overtime
};

void salary(pay);

int main()
{
	
	int payroll;
	char ch;
pay pay1;

	cout << setiosflags(ios::fixed) 			// show value as fixed decimal point
	     << setiosflags(ios::showpoint)			// show decimal point
	     << setprecision(2);		       		// show 2 decimals



//////////////////////////////////////////////////////////////////////////////////////////
//Menu                                                

cout <<"           Wayne Industries 2000 Payroll Sytem \n          ";
cout <<"Please select an option by entering a number from the menu below (1-5). \n";
cout <<" 1. Enter payroll information \n";
cout <<" 2. Update payroll information \n";
cout <<" 3. Calculate gross wages \n";
cout <<" 4. Print salary information \n";
cout <<" 5. Exit the payroll program \n";
cin >> payroll;

//////////////////////////////////////////////////////////////////////////////////////////
//Switch Functions                                 

switch(payroll)
{

case 1:
	salary(pay1);
	break;

case 2:
	cout << "2. You enter the payroll info here";
	break;

case 3:
	cout << "3. You enter the payroll info here";
	break;

case 4:
	cout << "4. You enter the payroll info here";
	break;

case 5:
	cout << "5. You enter the payroll info here";
	break;
}



//////////////////////////////////////////////////////////////////////////////////////////
//Function Statements                              

	void salary(pay1)
	{
		cout << "Enter the hourly wage of the worker: $"; 
		cin >> pay1.rop; 
		cout << "Enter the number of hours worked this week: "; 
		cin >> pay1.hours; 
	}
}

<< moderator edit: added [co[u][/u]de][/co[u][/u]de] tags >>

Recommended Answers

All 4 Replies

What type is pay1 ?

void salary(pay1)
   {
      cout << "Enter the hourly wage of the worker: $";
      cin >> pay1.rop;
      cout << "Enter the number of hours worked this week: ";
      cin >> pay1.hours;
   }

And you cannot define a function within another function. Now would be a good time to learn to indent code well.

What type is pay1 ?

void salary(pay1)
   {
      cout << "Enter the hourly wage of the worker: $";
      cin >> pay1.rop;
      cout << "Enter the number of hours worked this week: ";
      cin >> pay1.hours;
   }

And you cannot define a function within another function. Now would be a good time to learn to indent code well.

pay 1 is type float.

I don't understand where I am referencing a function in a function. Are you refering to the fact that I eneterd the function declaration as void salary(pay) but I referenced the function call and function definition as void salary(pay1) ?

I had to change it to void salary(pay1) in order to accesss the structure commands while coding. Don't know how else to describe it, when you type the dot and the structure variables come up in visual.

If I am going off on a different tangent I am sorry. Hope I answered your question and it made sense. And thank you for trying to help me.

I don't understand where I am referencing a function in a function. Are you refering to the fact that I eneterd the function declaration as void salary(pay) but I referenced the function call and function definition as void salary(pay1) ?

That's why I made the comment about indenting. This is what it really looks like:

int main()
{
   // ...

	void salary(pay1)
	{
		cout << "Enter the hourly wage of the worker: $"; 
		cin >> pay1.rop; 
		cout << "Enter the number of hours worked this week: "; 
		cin >> pay1.hours; 
	}
}

pay 1 is type float.

You might want to tell the compiler that important information.

I had to change it to void salary(pay1) in order to accesss the structure commands while coding. Don't know how else to describe it, when you type the dot and the structure variables come up in visual.

If I am going off on a different tangent I am sorry. Hope I answered your question and it made sense. And thank you for trying to help me.

Don't let the IDE help you do the wrong thing because it is more convenient.

Declare the prototype correctly. Then define the function outside of main . And by the way, you'll want to use pass-by-reference if you want to change an object's values within another function.

Hey Dave,

Sorry it has taken me so long to get back to you. Tech issues and other gremlins have been working overtime it seems.

I still don't have a complete grasp on all the concepts but there are a few lightbulbs that have been lit :) Thank you for your time and patience. I know a lot of people don't like to answer students questions because we have a reputation of just looking for a quick answer/fix and bugging out. I just wanted to let you know quickly that I appreciate your time and more importantly I have learned something.

Thank You!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.