Advertisement
syad28

UITM CS128 Tutorial Q16

Feb 14th, 2016
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.47 KB | None | 0 0
  1. #include <iostream>
  2. #include <string.h>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     float salary_input,max_salary=0,min_salary=9999,total_salary=0;
  9.     int totalSalaryBelow2k=0,count=0;
  10.     char staff_input[30],max_staff[30],min_staff[30];
  11.  
  12.     cout<<"Please enter staff name (enter X to exit) : ";
  13.         cin>>staff_input;
  14.    
  15. //use strcmp utk compare between char array
  16.     while(strcmp(staff_input,"X")){
  17.         cout<<"Please enter salary : ";
  18.         cin>>salary_input;
  19.  
  20.         //finding min salary and copying staff name in the variable
  21.         if(salary_input<min_salary){
  22.             min_salary=salary_input;
  23.             strcpy(min_staff,staff_input);
  24.         }
  25.  
  26.         //finding max salary and copying staff name in the variable
  27.         if(salary_input>max_salary){
  28.             max_salary=salary_input;
  29.             strcpy(max_staff,staff_input);
  30.         }
  31.  
  32.         //finding how much people with salary below rm2k
  33.         if(salary_input<2000)
  34.             totalSalaryBelow2k++;
  35.  
  36.         total_salary+=salary_input;
  37.         count++;
  38.  
  39.     cout<<"Please enter staff name (enter X to exit) : ";
  40.         cin>>staff_input;
  41.     }//end of loop
  42.  
  43.     float average = total_salary/count;
  44.     cout<<"\nHighest salary : "<<max_salary<<" ( "<<max_staff<<" )"<<endl;
  45.     cout<<"Lowest salary : "<<min_salary<<" ( "<<min_staff<<" )"<<endl;
  46.     cout<<"Average salary : "<<average<<endl;
  47.     cout<<"Number of staff for salary below RM2000 : "<<totalSalaryBelow2k<<endl;
  48.  
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement