Thread: employees & salary

  1. #1
    wise_ron wise_ron's Avatar
    Join Date
    May 2006
    Posts
    75

    employees & salary

    Hi, i have a little problem. I want this program to continue to ask the user how much is their hourly worked, until the user enters -1, this will end the program. Can any one give me some hints in how to do this.

    Code:
    #include<stdio.h>
    main()
    {
       float hours_worked, hourly_rate, salary, overtime_hours, overtime_salary, times_half, total_salary;
        
    	 printf("Enter hours worked(-1 to end): ");
    	 scanf("%f",&hours_worked); //stores variable hours_worked
    	 printf("Enter hourly rate of the worker ($00.00): ");
    	 scanf("%f",&hourly_rate);  //stores variable hourly_rate
       
    	if (hours_worked<=40)
    	{		
    	  salary= hours_worked*hourly_rate; // multiplication to get variable salary
    	  printf("Salary is $%0.2f", salary);
    	}
    	else if (hours_worked>=41)
    	{
    	  overtime_hours =hours_worked-40;  // calculations for overtime_salary
          salary =40*hourly_rate;
    	  times_half =overtime_hours*hourly_rate/2;
    	  overtime_salary =times_half+hourly_rate;
          total_salary =salary+overtime_salary;	
    	  printf("Employee worked %3.0f hour(s) overtime for a value of $%0.2f\n", overtime_hours, overtime_salary);
    	  printf("Salary is $%0.2f", total_salary); 
        }
    	//else if(hours_worked==-1) // i need to have something here when the there is -1 the program will end
    	
    	   
         return 0;
    		
    }
    Wise_ron
    One man's constant is another man's variable

  2. #2
    Just kidding.... fnoyan's Avatar
    Join Date
    Jun 2003
    Location
    Still in the egg
    Posts
    275
    Something like this....
    Code:
     float hours_worked=0;
    do {
    	 printf("Enter hours worked(-1 to end): ");
    	 scanf("%f",&hours_worked); //stores variable hours_worked
             hours_worked+=hours_worked;
    } while (hours_worked == -1);
    ....
    You also should check the validty of the answer entered by the use (for exmaple a negative value!)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. program for finding gross salary
    By newbcore in forum C Programming
    Replies: 7
    Last Post: 12-05-2008, 06:23 PM
  2. Find max profit among input salary
    By hlam in forum C Programming
    Replies: 8
    Last Post: 11-16-2008, 10:30 AM
  3. help me!!
    By lilmiss in forum C Programming
    Replies: 6
    Last Post: 09-23-2008, 04:51 PM
  4. Salary Range Calculator help please!! =(
    By bambino in forum C++ Programming
    Replies: 3
    Last Post: 04-20-2006, 06:17 PM
  5. Need help with small program to calculate a salary
    By Guti14 in forum C++ Programming
    Replies: 13
    Last Post: 01-11-2004, 05:54 PM