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 23-Sep-2003, 18:20
arek arek is offline
New Member
 
Join Date: Sep 2003
Posts: 1
arek is an unknown quantity at this point

Payroll program


so im writing this small program in C and im having trouble with it. here it is:
CPP / C++ / C Code:
/*WEEKLY PAYROLL OF MANAGERS AND N0N-MANAGERS
 *NAME: Arkadiusz Jaworski
 *CORE: 1.5
 *DATE: 09/24/2003
 */

#include <stdio.h>
int main ()
{
	  int id, status=0, numberemps=0;
	  double hours, rate, weeklypay, dues, netpay;
	  FILE *output;
	  output=fopen ("a:assn2output.out","w");

	  printf ("please enter ID#, -1 to stop > ");
	  scanf ("%d", &id);
	  while (id!=-1){
	  		 printf ("enter status. 1 for manager, 0 for non-manager > ");
			 scanf ("%d", &status);{
			 if (status==0)
					printf ("nonmanager");
			 if (status==1)
					printf ("manager");}
			 printf ("enter hours > ");
			 scanf ("%lf", &hours);
			 printf ("enter rate of pay > ");
			 scanf ("%lf", &rate);
			 if (hours > 40)
					weeklypay=40*rate+(hours-40)*1.5*rate;
			 else
					weeklypay=hours*rate;
			 if (status==0)
					dues=weeklypay-(weeklypay-15);
			 if (status==1)
					dues=weeklypay*.1;
			 netpay=weeklypay-dues;
			 fprintf (output, "Employee %d worked %.1f hours at $%.2f - %d\n", id, hours, rate, status);
			 fprintf (output, "Weekly pay $%.2f   Dues $%.2f   Net Pay $%.2f\n\n\n", weeklypay, dues, netpay);
			 numberemps++;
			 printf ("please enter ID#, -1 to end > ");
			 scanf ("%d", &id);
}
	  fprintf (output, "%d employees were processed", numberemps);
	  fclose (output);
	  return 0;
}

so then i put the values for prompt.....

and the outout is like that for example:


employee 123 worked 46.0 hours at $6.50 per hour 1
weekly pay $318.50 dues $31.85 net pay $286.65


employee 433 worked 46.0 hours at $6.50 per hour 1
weekly pay $318.50 dues $31.85 net pay $286.65


employee 453 worked 46.0 hours at $6.50 per hour 0
weekly pay $318.50 dues $31.85 net pay $286.65


employee 574 worked 46.0 hours at $6.50 per hour 0
weekly pay $318.50 dues $31.85 net pay $286.65



-----
do u see where i put highlighted with bold text?
in that place i want for value od status=0 to prin in that place NONMANAGER and for status=1 >> MANAGER

so here is how i want it to be:

employee 123 worked 46.0 hours at $6.50 per hour manager
weekly pay $318.50 dues $31.85 net pay $286.65


employee 433 worked 46.0 hours at $6.50 per hour manager
weekly pay $318.50 dues $31.85 net pay $286.65



----
of course with different values for hours and rate....

anyone can help me? thanx in advance
  #2  
Old 19-Feb-2010, 02:47
Nila Nila is offline
New Member
 
Join Date: Feb 2010
Posts: 9
Nila is on a distinguished road

Re: Payroll program


You can get the output as you want by run the following code. I removed and added some of the lines in your code.


#include <stdio.h>
#include <malloc.h>
int main ()
{
int id, status=0, numberemps=0;
double hours, rate, weeklypay, dues, netpay;
char *stat; // Added line.
FILE *output;
stat=malloc(100); // Allocate memory to the variable.
output=fopen ("a1.out","w");

printf ("please enter ID#, -1 to stop > ");
scanf ("%d", &id);
while (id!=-1){
printf ("enter status. 1 for manager, 0 for non-manager > ");
scanf ("%d", &status);
printf ("enter hours > ");
scanf ("%lf", &hours);
printf ("enter rate of pay > ");
scanf ("%lf", &rate);
if (hours > 40)
weeklypay=40*rate+(hours-40)*1.5*rate;
else
weeklypay=hours*rate;
if (status==0)
{
stat="non manager"; // Assign the value to the stat variable.
dues=weeklypay-(weeklypay-15);
}
if (status==1)
{
stat="manager";
dues=weeklypay*.1;
}
netpay=weeklypay-dues;
fprintf (output, "Employee %d worked %.1f hours at $%.2f per hour %s \n", id, hours, rate, stat);
fprintf (output, "Weekly pay $%.2f Dues $%.2f Net Pay $%.2f\n\n\n", weeklypay, dues, netpay);
numberemps++;
printf ("please enter ID#, -1 to end > ");
scanf ("%d", &id);
}
fprintf (output, "%d employees were processed", numberemps);
fclose (output);
return 0;
}
  #3  
Old 19-Feb-2010, 05:32
Mexican Bob's Avatar
Mexican Bob Mexican Bob is offline
Regular Member
 
Join Date: Mar 2008
Location: Chicxulub, Yucatán
Posts: 342
Mexican Bob is a jewel in the roughMexican Bob is a jewel in the roughMexican Bob is a jewel in the roughMexican Bob is a jewel in the rough

Re: Payroll program


Unfortunately you did not pay any attention to the guidelines, which clearly state that you must put code into the appropriate tags to preserve reasonable formatting.

Also, you're replying to a post that is coming up on 7 years old. I'm guessing that "arek" probably already figured out the problem by now or gave up.


MxB
 
 

Recent GIDBlogInstall Adobe Flash - Without Administrator Rights by LocalTech

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

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

All times are GMT -6. The time now is 00:12.


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