GIDForums  

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

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 21-Mar-2007, 21:51
lyojarhhs lyojarhhs is offline
New Member
 
Join Date: Mar 2007
Posts: 2
lyojarhhs is on a distinguished road

Pointers


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.

CPP / C++ / C 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;
}
Last edited by admin II : 22-Mar-2007 at 08:06. Reason: Please surround your C code with [cpp] ... [/cpp]
  #2  
Old 22-Mar-2007, 00:46
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,258
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all

Re: Pointers


Start by reading the Guidelines
Also this about main()

You need to actually put a loop in main() in order to "loop the entire program over again," probably a do/while loop is best.

How much of the program works? Since we're coming in cold, you need to give us a little information, not just a couple hundred line of code and ask us to help fix it....
__________________

Got a cough? Go home tonight and eat a whole box of Ex-Lax. Tomorrow, you'll be afraid to cough.
-- Pearl Williams
  #3  
Old 22-Mar-2007, 13:07
lyojarhhs lyojarhhs is offline
New Member
 
Join Date: Mar 2007
Posts: 2
lyojarhhs is on a distinguished road

Re: Pointers


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:

CPP / C++ / C 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;
}
}
Last edited by LuciWiz : 22-Mar-2007 at 15:43. Reason: Please insert your C/C++ code between [cpp] & [/cpp] tags
  #4  
Old 22-Mar-2007, 13:32
KenJackson KenJackson is offline
Junior Member
 
Join Date: Nov 2006
Location: Maryland, USA
Posts: 30
KenJackson is on a distinguished road

Re: Pointers


Instead of this:
CPP / C++ / C Code:
get_employee_info()
{
    int employee_number, gross_pay, week, rate, hours_worked, salary, weekly_salary;
    char hourly_salary;
You could do this:
CPP / C++ / C Code:
get_employee_info(int *employee_number, int *gross_pay, int *week, int *rate,
                  int *hours_worked, int *salary, int *weekly_salary, 
                  char *hourly_salary)
{
//...
Last edited by admin : 23-Mar-2007 at 20:52. Reason: Attempt at correcting previous edits
  #5  
Old 22-Mar-2007, 14:08
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,258
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all

Re: Pointers


Looks like I completely wasted my time responding, and trying to help....

Hint taken.
__________________

Got a cough? Go home tonight and eat a whole box of Ex-Lax. Tomorrow, you'll be afraid to cough.
-- Pearl Williams
  #6  
Old 23-Mar-2007, 14:44
ahbi82 ahbi82 is offline
Member
 
Join Date: Jul 2006
Posts: 115
ahbi82 will become famous soon enough

Re: Pointers


Hi lyojarhhs,

First of all, do you know what a pointer is?
Well the answer in short is: It is pointing to the address of a variable or NULL (which points to nothing)

A value for a vairalble is stored at a certain memory address. In addition, a pointer is also a memory address, in which storing the address of the variable its pointing to.

For example:

CPP / C++ / C Code:
int x = 10   // for example x is stored in address 0x0001

/* '&' preceeding x means the address of x.
'*' has two meanings.
1) when using during declaration its means that its a pointer to a certain type.
2.) it is also a in-direction / de-referencing operator. */
int* x_ptr = &x   // so now x_ptr is storing 0x0001

// demo de0referencing
*x_ptr = 20;    so now x has the value 20.


One main advantage of using pointers is to passing by reference to functions instead of passing by value. And also to save resources as values need no be duplicated as passing by value. The later is more important in embedded systems where resources are limited.

Hope this helps!!!
  #7  
Old 24-Mar-2007, 21:01
admin's Avatar
admin admin is offline
Administrator
 
Join Date: Sep 2002
Posts: 774
admin will become famous soon enough

Re: Pointers


Some off-topic discussions were moved to http://www.gidforums.com/t-13893.html.
__________________
Custom BB codes you can use here:
[HTML] | [C++] | [CSS] | [JAVA] | [PY] | [VB]
 
 

Recent GIDBlogStupid Management Policies 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
Sort an array of structures sassy99 C Programming Language 10 15-Feb-2007 08:46
Pointer Usage in C++: Beginner to Advanced varunhome C++ Forum 0 19-Aug-2005 10:25
[Tutorial] Pointers in C (Part II) Stack Overflow C Programming Language 0 27-Apr-2005 18:36
[Tutorial] Pointers in C (Part I) Stack Overflow C Programming Language 1 08-Apr-2005 19:35

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

All times are GMT -6. The time now is 16:44.


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