![]() |
|
#1
|
|||
|
|||
Payroll programso im writing this small program in C and im having trouble with it. here it is:
CPP / C++ / C Code:
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
|
|||
|
|||
Re: Payroll programYou 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
|
||||
|
||||
Re: Payroll programUnfortunately 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 GIDBlog
Install Adobe Flash - Without Administrator Rights by LocalTech
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The