payroll problem

This is a discussion on payroll problem within the C Programming forums, part of the General Programming Boards category; ok each part of this code works fine but i neeed it to retturn to a certian user prompt and ...

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    23

    payroll problem

    ok each part of this code works fine but i neeed it to retturn to a certian user prompt and have tried everything i know.

    Code:
    /* payroll program to calculate weeks pay */
    #include <stdio.h>
    
    int main() /* starts execution */
    {
        // hourly worker
    	float work_hours = 0;     /* hours worked */
    	float rate = 0;           /* pay per hour */
    	
    	//Salary-Manager 
    	float sal_pay = 0;        /* pay per salary */
        
    	// commission
    	const double base_sal = 245.00;  /* pay per base salary */
    	float comm = 0;           /* commission earned */
    	float sold = 0;           /* amount sold to derive commissions */
    	const double comm_rate = 0.15; /* set rate of commission */
        
    	// peice worker
    	int unit = 0;             /* unit built for sale which worker is paid per */
    	float unit_pay = 0;       /* pay per each unit */
        
        int worker;/* unit to represent pay code for muiltiple classes of workers */
    	
    	float pay = 0;            /* the total pay woker will recive for week */
    
    
    	printf ("Thank You.\n"); // menu prompt to select workers pay code
    	printf ("1 Hourly\t");
    	printf ("2 Manager / Salary\n");
    	printf ("3 Commission\t");
    	printf ("4 Peice\n");
    	printf ("Or press -1 to end\n");
    
    	while (worker !=  -1) // start whole loop
    	{
    
    		scanf ("%d", &worker); // user prompt - workers pay code
    
    		
    		
    		 
    		// loop for hour worker
    		while (worker == 1) {
    		
    			printf ("Enter # of hours worked for the week :\n", work_hours); 
    			scanf  ("%f", &work_hours);
    			printf ("Enter hourly pay rate of worker ($00.00):\n", rate);
    			scanf  ("%f", &rate);
    
    			if  (work_hours <= 40) { 
    			pay = rate * work_hours;
    			
    		}
    
    		else {
    			pay = rate * 40 + (rate * 1.5 * (work_hours - 40));
    		}
    		
    		printf ("Salary is %.2f\n", pay);
    		
    		
    		} // end hourly worker loop
    	
    
            
    		// loop for manager-salary
    	    while (worker == 2) {
    
    		printf ("Please print Manager/Salary workers set pay:", sal_pay);
            scanf  ("%f", &sal_pay);
    
         		pay = 0;
    	    	pay = sal_pay;
            
    		    printf ("Salary is %.2f\n", pay); 
    		}// end manager-salary loop
    
    		
    		
    
            // commission loop
    	    while (worker == 3) {
    		
    		printf ("Please enter total sales for the week:\n" , sold);
    		scanf  ("%f" , &sold);
    
    			comm = (float) sold * (double) comm_rate;
    			pay = 0;
    			pay = (float) comm + base_sal;
    
    			printf ("Toatl pay with $245.00 salary + earnd Commissions is:  $ %.2f\n" , pay);
    			
    		} // end commission loop
    
    		
    
        // peice worker loop started
    	while (worker == 4) {
    		
    		printf ("Please enter the unit the worker built for the week:\n", unit);
    		scanf  ("%d", &unit);
    
    		
    		printf ("Please enter the pay for unit:", unit_pay);
    		scanf  ("%f", &unit_pay);
    
    		pay = 0;
    		pay = unit * (float) unit_pay;
    
    		printf ("This unit workers pay is %.2f\n", pay);
    		        
    	} // end peice worker loop
    
    
    
    	} // end whole loop
    	
    
    	return (0);
    	} // end main
    ive used break and continue at the end of each while loop and can't get it to return to the main loop where it will allow me to enter a diffrent paycode to work on located at line 38 which is the line i would like to retun once a pay is figured
    Code:
    	printf ("Thank You.\n"); // menu prompt to select workers pay code
    	printf ("1 Hourly\t");
    	printf ("2 Manager / Salary\n");
    	printf ("3 Commission\t");
    	printf ("4 Peice\n");
    	printf ("Or press -1 to end\n");
    
    	while (worker !=  -1) // start whole loop
    	{
    
    		scanf ("%d", &worker); // user prompt - workers pay code
    thanks,
    joe

  2. #2
    Registered User
    Join Date
    Nov 2006
    Posts
    176
    worker == 1
    is always true when worker = 1
    same for worker ==2 etc.
    all your inner loops are infinite, maybe just use if not while

  3. #3
    Registered User
    Join Date
    Nov 2006
    Posts
    23
    that helps with the infinte looping changing all inner whiles to ifs
    but if i use break it exits the program completly

    is their like a way to use the return command to start the program back to the begining once its caulculated the pay????

  4. #4
    Registered User
    Join Date
    Nov 2006
    Posts
    176
    but if i use break it exits the program completly
    -- correct since it will break from the 1 while loop you have now

    return isn't what your looking for.

    where ever you want it to start over from move the while loop up to there

    ie.
    to redisplay the options
    have
    Code:
    while (worker !=  -1) // start whole loop
    {
            printf ("Thank You.\n"); // menu prompt to select workers pay code
    	printf ("1 Hourly\t");
    	printf ("2 Manager / Salary\n");
    	printf ("3 Commission\t");
    	printf ("4 Peice\n");
    	printf ("Or press -1 to end\n");
    ...
    ...
    don't forget to initialize worker to 0, or instead of while, use a do while loop

  5. #5
    Registered User
    Join Date
    Nov 2006
    Posts
    23
    thanks sl4nted

    here is the corection to the code it works like a charm
    Code:
    	while (worker !=  -1) // start whole loop
    	{
    		worker = 0;// reset paycode
    	printf ("Thank You.\n"); // menu prompt to select workers pay code
    	printf ("1 Hourly\t");
    	printf ("2 Manager / Salary\n");
    	printf ("3 Commission\t");
    	printf ("4 Peice\n");
    	printf ("Or press -1 to end\n");
    
    	
    
    		scanf ("%d", &worker); // user prompt - workers pay code

  6. #6
    Registered User
    Join Date
    Nov 2006
    Posts
    176
    worker = 0;// reset paycode

    that should be before while

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  2. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 09:38 AM
  3. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 03:51 PM
  4. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 07:54 PM
  5. beginner problem
    By The_Nymph in forum C Programming
    Replies: 4
    Last Post: 03-05-2002, 05:46 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21