473,785 Members | 2,816 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

find highest salary employee using for loop and arrays

32 New Member
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 28107
horace1
1,510 Recognized Expert Top Contributor
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 New Member
please iam newbie
Feb 7 '07 #3
apking
32 New Member
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 Recognized Expert Top Contributor
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
rajesh6695
96 New Member
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....

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
kunal pandey
1 New Member
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
3035
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). I have a dataset as follows (1 week to keep it short): Employee 1 - Date 1 Employee 1 - Date 2
3
2470
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 employee values(3,'sunil',11,4500) insert into employee values(4,'sridhar',22,2000) insert into employee values(5,'ramesh',33,12000) insert into employee values(6,'srini',22,16000) insert into employee values(7,'sashi',33,54000)
1
11544
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 receive a 6% raise, one rated good will receive a 4% raise, and one rated poor will receive a 1.5% raise. Add the if... else... statements to program Salary to make it run as described above. //...
22
14014
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 salary.
2
9191
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
14782
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 40 hours worked by each employee and pays "time-and-a-half" for all hours worked in excess of 40 hours. You are given a list of the employees of the company, the number of hours each employee worked last week and the hourly rate of each employee....
15
10832
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", which depends on it. SQLSTATE=42893 Then I tried to do
0
4571
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 columns to make a derived column. When I run my code, I get this error: ------------
5
3873
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 EmployeeTest class. */ public class EmployeeTest {
0
9645
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10152
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10092
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9950
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6740
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2880
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.