Welcome to Dream.In.Code
Become a C++ Expert!

Join 149,492 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,297 people online right now. Registration is fast and FREE... Join Now!




pointers

 
Reply to this topicStart new topic

pointers

jaclyn_85
21 Mar, 2007 - 07:26 PM
Post #1

New D.I.C Head
*

Joined: 16 Sep, 2006
Posts: 17


My Contributions

My program has functions that need to be able to access data from each other. So basically, I need to know where to put the pointers, as much help as you could give me...

Also, my last function is supposed to loop the entire program over again if they answer yes, how do i do this?
thanks for your time.


CODE

#include <stdio.h>

main()
{

get_employee_info();

ltb_calculation();

overtime_rate();

employment_insurance();

canada_pension_plan();

federal_taxes();

output_form();

loop();

}

get_employee_info()
{
int employee_number, gross_pay, week, rate, hours_worked, salary, weekly_salary;
char hourly_salary;

printf ("Please enter your employee number:\n");
scanf ("%d", &employee_number);

printf ("Please enter for which week ending (YYYYMMDD):\n");
scanf ("%d", &week);

getchar();

printf ("Please enter if you are an Hourly (h) or Salary (s) paid employee:\n");
scanf("%c", &hourly_salary);


if( hourly_salary == 'h')
  {
    
  printf ("Please enter your rate of pay:\n");
  scanf ("%d", &rate);
  printf ("Please enter the number of hours worked:\n");
scanf ("%d", &hours_worked);
  
  weekly_salary= rate * hours_worked;
  gross_pay= weekly_salary * 52;    
  }
  
if (hourly_salary == 's')
{
  
  printf ("Please enter your annual salary:\n");
  scanf ("%d", &salary);
  weekly_salary= salary/52;
  gross_pay= salary;
  }
}
  
ltb_calculation() {
int deduction, ltb;
double grosspay;  

if ((grosspay / 100)  > 0)
{
ltb= grosspay / 100;
if (ltb > 50)
{
  
ltb == 50;

}
deduction= ltb * 2;
grosspay= grosspay - deduction;
}
}
overtime_rate()
{
double hourly_salary,overtime_rate, overtime_hours, overtime_pay, grosspay;
double hours, rate;

if (hourly_salary == 'h' && hours > 44)
{overtime_rate= 1.5 * rate;
overtime_hours= hours - 44;
overtime_pay= overtime_hours * overtime_rate;
grosspay= grosspay + overtime_pay;
}
}
employment_insurance()
{
double ei, weekly_salary;

ei= weekly_salary * .014;
if (ei > 11.80)
{
ei= 11.80;
}
}

canada_pension_plan()
{
double deduction, grosspay, pension;

deduction= grosspay * .016;
pension= deduction * 700;  
}

federal_taxes()
{
double annual_salary, initial_amount, base_amount, additional_amount;
double remainder_amount, fed_tax, remainder, provincial_tax;
if (annual_salary < 20,000)
{
initial_amount= annual_salary * .16;
}

if (annual_salary >= 20,000)
{
base_amount= 20,000 * .16;
}

remainder= annual_salary - 20,000;

if (remainder >= 20,000)
{
additional_amount= 20,000 * .23;
}

remainder_amount= remainder * .29;

fed_tax= initial_amount + base_amount + additional_amount + remainder_amount;

provincial_tax= fed_tax *.47;
fed_tax= fed_tax + provincial_tax;
}


output_form()
{
char hourly_salary;
double deductions, net_pay, fed_tax, ei, ltb, pension, gross_pay;
int employee_no, week, rate, hours_worked, salary;

deductions= fed_tax + ei + ltb + pension;
net_pay= gross_pay - deductions;


printf ("bob jones Payroll Systems\n");

printf ("102 Orfus Road, Downsview ON\n\n");

printf ("Employee Number:%d         For Week Ending:%d, employee_no, week\n\n");

if (hourly_salary == 's')
{
printf ("Salary Paid : %.2d, salary\n\n");
}

if (hourly_salary == 'h')
{
printf ("Hourly Rate:     %.2d       Hours Worked:   %d, rate, hours_worked\n\n"
}

printf("GROSS PAY:                                 %.2d, gross_pay\n\n");

printf ("DEDUCTIONS:\n");
printf ("Long Term Benefits:                          %.22d, ltb\n");
printf ("Employment Insurance:                       %.2d, ei\n");  
printf ("Canada Pension Plan:                        %.2d, pension\n");
printf ("Federal Tax:                               %.2d, fed_tax\n\n");

printf ("TOTAL DEDUCTIONS:                          %.2d, deductions\n\n");

printf ("NET PAY:                                    %.2d, net_pay\n");
}

loop()
{    
char response;

printf ("Would you like to enter more data? ( 'y' or 'n')\n");
getchar();
scanf ("%c", &response);

if (response == 'y')
return 1;
else    
return 0;
}

User is offlineProfile CardPM
+Quote Post

NickDMax
RE: Pointers
21 Mar, 2007 - 08:47 PM
Post #2

2B||!2B
Group Icon

Joined: 18 Feb, 2007
Posts: 2,867



Thanked: 53 times
Dream Kudos: 550
My Contributions
I don't think you are asking enough of main... Or perhapse you need to combine this all into a class (if you are in c++). For example, the last function really CAN'T just make the program loop again (it technically can, but it would require WAY more work than you want to get into). However if it is in a control structure in main it can:
CODE

main()
{
do {
get_employee_info();
ltb_calculation();
overtime_rate();
employment_insurance();
canada_pension_plan();
federal_taxes();
output_form();
} while(loop());
All loop has to do is return a nonzero value and the program will loop.

Now to get the other functions to play nice decalare some structures and varibles and pass values and pointers to the function.

CODE
typedef scruct {
int employee_number;
char hourly_salary;
int rate;
int salary;
} EmployeeRecord;

void get_employee_info(EmployeeRecord &emplyee);

int main()
{
    EmployeeRecord emp;
    get_employee_info(emp);
    ...
}

etc etc.

All of these functions can take in data, and they can return data. The above is a rather usless example as it is only meant to give you a direction. Each function should do 1 thing... it can be a complex thing like "get all the emplayee data needed from the user" but once it has done that it should then pass the data on to the next function that needs it... which again should do "one thing".

When I say "one thing" it is really misleading as a function may carry out many tasks, but they should all be logicly related to one another.

User is offlineProfile CardPM
+Quote Post

jaclyn_85
RE: Pointers
22 Mar, 2007 - 09:57 AM
Post #3

New D.I.C Head
*

Joined: 16 Sep, 2006
Posts: 17


My Contributions
So, i understand the do/while loop.. but i dont really get the 2nd part you tried explaining, i'm using C not C++ so there's no struct..
I just don't know the way to pass the information given to one function to the next, and then so on... For example i need to pass the "gross_pay" from get_employee_info to the ltb function... i first declare the variable in main? and then where do the asterisks or ampersands go?
this is the part of the code i'm speaking about:

CODE

get_employee_info()
{
int employee_number, gross_pay, week, rate, hours_worked, salary, weekly_salary;
char hourly_salary;

printf ("Please enter your employee number:\n");
scanf ("%d", &employee_number);

printf ("Please enter for which week ending (YYYYMMDD):\n");
scanf ("%d", &week);

getchar();

printf ("Please enter if you are an Hourly (h) or Salary (s) paid employee:\n");
scanf("%c", &hourly_salary);


if( hourly_salary == 'h')
  {
    
  printf ("Please enter your rate of pay:\n");
  scanf ("%d", &rate);
  printf ("Please enter the number of hours worked:\n");
scanf ("%d", &hours_worked);
  
  weekly_salary= rate * hours_worked;
  gross_pay= weekly_salary * 52;    
  }
  
if (hourly_salary == 's')
{
  
  printf ("Please enter your annual salary:\n");
  scanf ("%d", &salary);
  weekly_salary= salary/52;
  gross_pay= salary;
  }
}
  
ltb_calculation() {
int deduction, ltb;
double gross_pay;  

if ((gross_pay / 100)  > 0)
{
ltb= gross_pay / 100;
if (ltb > 50)
{
  
ltb == 50;

}
deduction= ltb * 2;
gross_pay= gross_pay - deduction;
}
}













QUOTE(NickDMax @ 21 Mar, 2007 - 09:47 PM) *

I don't think you are asking enough of main... Or perhapse you need to combine this all into a class (if you are in c++). For example, the last function really CAN'T just make the program loop again (it technically can, but it would require WAY more work than you want to get into). However if it is in a control structure in main it can:
CODE

main()
{
do {
get_employee_info();
ltb_calculation();
overtime_rate();
employment_insurance();
canada_pension_plan();
federal_taxes();
output_form();
} while(loop());
All loop has to do is return a nonzero value and the program will loop.

Now to get the other functions to play nice decalare some structures and varibles and pass values and pointers to the function.

CODE
typedef scruct {
int employee_number;
char hourly_salary;
int rate;
int salary;
} EmployeeRecord;

void get_employee_info(EmployeeRecord &emplyee);

int main()
{
    EmployeeRecord emp;
    get_employee_info(emp);
    ...
}

etc etc.

All of these functions can take in data, and they can return data. The above is a rather usless example as it is only meant to give you a direction. Each function should do 1 thing... it can be a complex thing like "get all the emplayee data needed from the user" but once it has done that it should then pass the data on to the next function that needs it... which again should do "one thing".

When I say "one thing" it is really misleading as a function may carry out many tasks, but they should all be logicly related to one another.


User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 1/7/09 05:41PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month