469,890 Members | 2,107 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,890 developers. It's quick & easy.

find highest salary employee using for loop and arrays

32
please write the programe in c language for this

Accept 5 Employee details to find highest salary employe name using for loop and arrays


Thanks in advance
Feb 7 '07 #1
6 25223
horace1
1,510 Expert 1GB
please write the programe in c language for this

Accept 5 Employee details to find highest salary employe name using for loop and arrays


Thanks in advance
The experts on this site are more than happy to help you with your problem but we cannot do your assignment for you. Attempt the assignment yourself first and post questions regarding any difficulties you have or about a particular function of the code that you don't know how to achieve.
Feb 7 '07 #2
apking
32
please iam newbie
Feb 7 '07 #3
apking
32
Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. main()
  3. {
  4.     char employeeName[5][20],employeeSalary[5];
  5.     int i;
  6.     int maxSalary=0, maxEmpl=-1;
  7.     for(i=0;i<5;i++)
  8.     {
  9.         printf("Enter details of employee no. %d :",i+1);
  10.         scanf("%s",employeeName[i];
  11.         scanf("%d",&employeeSalary[i]);
  12.         if(employeeSalary[i]>maxSalary)
  13.         {
  14.             maxSalary=employeeSalary[i];
  15.             maxEmpl=i;
  16.         }
  17.     }
  18.     printf("Employee %s has the max salary %d", employeeName[maxEmpl],employeeSalary[maxEmpl]);
  19. }
Feb 7 '07 #4
horace1
1,510 Expert 1GB
you had a missing ) but otherwise the program is OK
Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. main()
  3. {
  4. char employeeName[5][20],employeeSalary[5];
  5. int i;
  6. int maxSalary=0, maxEmpl=-1;
  7. for(i=0;i<5;i++)
  8.   {
  9.   printf("Enter details of employee no. %d :",i+1);
  10.   scanf("%s",employeeName[i]);  // ** missing )
  11.   scanf("%d",&employeeSalary[i]);
  12.   if(employeeSalary[i]>maxSalary)
  13.      {
  14.      maxSalary=employeeSalary[i];
  15.      maxEmpl=i;
  16.      }
  17.   }
  18. printf("Employee %s has the max salary %d", employeeName[maxEmpl],employeeSalary[maxEmpl]);
  19. }
  20.  
it is a good idea to indent the code as it make the overall structure clearer
Feb 7 '07 #5
While comparing you are trying to compare the Char with an int (i.e Salary)...
as a beginner try to study the multidimensional array of strings and then try to implement it where at that time also you have to convert that salary into an integer by using atoi then only you can compare it...

Better see the below program will help you which is taken only a integer that to single dimensional array....

Note: you have to enter the Emp no as a integer..

Example
Emp no is 6695 or 66785 like thatnot excedding 32767
and salary can exceed see the datatype....

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <conio.h>
  3. int main()
  4. {
  5.     int emp[10]
  6.     unsigned int sal[10];
  7.     int i,j=0,
  8.     unsigned int max=0;
  9.     clrscr();
  10.     for(i=0;i<3;i++)
  11.     {
  12.         printf("Enter the Emp No: ");
  13.         scanf("%d",&emp[i]);
  14.         printf("Enter the Salary: ");
  15.         scanf("%u",&sal[i]);
  16.         if(sal[i]>max)
  17.         {
  18.             j=i;
  19.         }
  20.     }
  21.     printf("The Highest salry person is %d and his salary is %u",emp[j],sal[j]);
  22.     getch();
  23.     return 0;
  24. }
Feb 7 '07 #6
why you have used k=-1?i mean why -1?
Jan 16 '17 #7

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

17 posts views Thread by Justin Emlay | last post: by
1 post views Thread by sallyk57 | last post: by
8 posts views Thread by hmmtn | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.