•
•
•
•
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
![]() |
•
•
Join Date: Oct 2005
Posts: 3
Reputation:
Rep Power: 0
Solved Threads: 0
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.
<< moderator edit: added
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;
}
}[code][/code] tags >> What type is And you cannot define a function within another function. Now would be a good time to learn to indent code well.
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;
}•
•
Join Date: Oct 2005
Posts: 3
Reputation:
Rep Power: 0
Solved Threads: 0
•
•
•
•
Originally Posted by Dave Sinkula
What type ispay1?And you cannot define a function within another function. Now would be a good time to learn to indent code well.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.
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.
•
•
•
•
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) ?
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.
•
•
•
•
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.
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. •
•
Join Date: Oct 2005
Posts: 3
Reputation:
Rep Power: 0
Solved Threads: 0
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!
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!
![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- calculate the grades for a student using if..else statements. (Java)
- Requesting Querystring (ASP)
- Quiet student (Computer Science and Software Design)
- Querying database records (Visual Basic 4 / 5 / 6)
Other Threads in the C++ Forum
- Previous Thread: C books
- Next Thread: Functions and Array help



Linear Mode