473,405 Members | 2,338 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

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 27982
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

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

Similar topics

17
by: Justin Emlay | last post by:
I'm hopping someone can help me out on a payroll project I need to implement. To start we are dealing with payroll periods. So we are dealing with an exact 10 days (Monday - Friday, 2 weeks). ...
3
by: satish | last post by:
create table employee(empid int,empname varchar(20),managerid int not null, sal int) insert into employee values(1,'ranga',22,5000) insert into employee values(2,'satish',22,8000) insert into...
1
by: sallyk57 | last post by:
Help with following Programs: Write two programs one where the performance rating here shoud be entered as a int where Excellent =1, Good= 2, Poor=3. an employee who is rated excellent will...
22
by: ranjitkumar | last post by:
Hi everybody, create table employee { empno char(5) primay key, name varchar2(30), salary number(5,2) }; 1. For the above table how to find the employee with the third highest...
2
by: partha das | last post by:
sir i need a single sql query it may be sub query need to retrive the 5th highest salary from a employee table
8
by: hmmtn | last post by:
I would appreciate any help on this one. Assignment is as follows: Develop a program that will determine the gross pay for each of several employees. The company pays "straight time" for the first...
15
by: uwcssa | last post by:
I try to drop a table as: I got: During SQL processing it returned: SQL0478N The object type "TABLE" cannot be dropped because there is an object "sch.SQL070515104729271", of type "FUNCTION",...
0
by: SMH | last post by:
Hi All, I am currently learning .Net 2, studying for 70-528. I've hit a bit of a brick wall with DataColumn.Expression. As I understand it, this can be used to (For example) concatenate two...
5
by: cart1443 | last post by:
So I know I need to add a few more lines somewhere to make this work, but I'm not sure how. // Lab 3: EmployeeTest.java // Application to test class Employee. /* Begin class declaration of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.