User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 426,915 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,324 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 2024 | Replies: 4
Reply
Join Date: Oct 2005
Posts: 3
Reputation: Batman007 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Batman007 Batman007 is offline Offline
Newbie Poster

Student requesting help - Please!

  #1  
Oct 20th, 2005
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 [code][/code] tags >>
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Apr 2004
Posts: 3,640
Reputation: Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light 
Rep Power: 17
Solved Threads: 143
Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Student requesting help - Please!

  #2  
Oct 20th, 2005
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.
Reply With Quote  
Join Date: Oct 2005
Posts: 3
Reputation: Batman007 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Batman007 Batman007 is offline Offline
Newbie Poster

Re: Student requesting help - Please!

  #3  
Oct 20th, 2005
Originally Posted by Dave Sinkula
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.
Reply With Quote  
Join Date: Apr 2004
Posts: 3,640
Reputation: Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light 
Rep Power: 17
Solved Threads: 143
Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Student requesting help - Please!

  #4  
Oct 20th, 2005
Originally Posted by Batman007
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; 
	}
}
Originally Posted by Batman007
pay 1 is type float.
You might want to tell the compiler that important information.
Originally Posted by Batman007
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.
Reply With Quote  
Join Date: Oct 2005
Posts: 3
Reputation: Batman007 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Batman007 Batman007 is offline Offline
Newbie Poster

Re: Student requesting help - Please!

  #5  
Nov 3rd, 2005
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!
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 11:35 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC