find highest salary employee using for loop and arrays

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • apking
    New Member
    • Feb 2007
    • 32

    find highest salary employee using for loop and arrays

    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
  • horace1
    Recognized Expert Top Contributor
    • Nov 2006
    • 1510

    #2
    Originally posted by apking
    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.

    Comment

    • apking
      New Member
      • Feb 2007
      • 32

      #3
      please iam newbie

      Comment

      • apking
        New Member
        • Feb 2007
        • 32

        #4
        Code:
        #include <stdio.h>
        main()
        {
            char employeeName[5][20],employeeSalary[5];
            int i;
            int maxSalary=0, maxEmpl=-1;
            for(i=0;i<5;i++)
            {
                printf("Enter details of employee no. %d :",i+1);
                scanf("%s",employeeName[i];
                scanf("%d",&employeeSalary[i]);
                if(employeeSalary[i]>maxSalary)
                {
                    maxSalary=employeeSalary[i];
                    maxEmpl=i;
                }
            }
            printf("Employee %s has the max salary %d", employeeName[maxEmpl],employeeSalary[maxEmpl]);
        }
        Last edited by Frinavale; Feb 14 '17, 09:29 PM.

        Comment

        • horace1
          Recognized Expert Top Contributor
          • Nov 2006
          • 1510

          #5
          you had a missing ) but otherwise the program is OK
          Code:
          #include <stdio.h>
          main()
          {
          char employeeName[5][20],employeeSalary[5];
          int i;
          int maxSalary=0, maxEmpl=-1;
          for(i=0;i<5;i++)
            {
            printf("Enter details of employee no. %d :",i+1);
            scanf("%s",employeeName[i]);  // ** missing )
            scanf("%d",&employeeSalary[i]);
            if(employeeSalary[i]>maxSalary)
               {
               maxSalary=employeeSalary[i];
               maxEmpl=i;
               }
            }
          printf("Employee %s has the max salary %d", employeeName[maxEmpl],employeeSalary[maxEmpl]);
          }
          it is a good idea to indent the code as it make the overall structure clearer

          Comment

          • rajesh6695
            New Member
            • Oct 2006
            • 96

            #6
            While comparing you are trying to compare the Char with an int (i.e Salary)...
            as a beginner try to study the multidimensiona l 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....

            Code:
            #include <stdio.h>
            #include <conio.h>
            int main()
            {
                int emp[10]
                unsigned int sal[10];
                int i,j=0,
                unsigned int max=0;
                clrscr();
                for(i=0;i<3;i++)
                {
                    printf("Enter the Emp No: ");
                    scanf("%d",&emp[i]);
                    printf("Enter the Salary: ");
                    scanf("%u",&sal[i]);
                    if(sal[i]>max)
                    {
                        j=i;
                    }
                }
                printf("The Highest salry person is %d and his salary is %u",emp[j],sal[j]);
                getch();
                return 0;
            }

            Comment

            • kunal pandey
              New Member
              • Jan 2017
              • 1

              #7
              why you have used k=-1?i mean why -1?

              Comment

              Working...