I'm using dev-c++ to build my programes.
when i enter info of "myEmployee" then it is error "don't send"
Fix and interpret it for me,please!
Thank so much.
Code:
#include <sstream>
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <iostream>
using namespace std;
typedef struct {
int day;
int month;
int year;
} Date;
typedef struct employee{
string name;
Date birthDay;
string role;
double salary;
} Employee;
void InitEmployee(Employee *myEmployee,int length);
Employee searchSalaryMax(Employee *myEmployee,int length);
Employee searchSalaryMin(Employee *myEmployee,int length);
void display(Employee myEmployee);
void InitEmployee(Employee *myEmployee,int length){
myEmployee=new Employee[length];
for(int i=0;i<length;i++){
cout<<"Numble: "<<i<<endl;
cout<<"Name: ";
fflush(stdin);
getline(cin,myEmployee[i].name);
cout<<"Day of birth: ";
cin>>myEmployee[i].birthDay.day;
cout<<"Month of birth: ";
cin>>myEmployee[i].birthDay.month;
cout<<"Year of birth: ";
cin>>myEmployee[i].birthDay.year;
cout<<"Role: ";
fflush(stdin);
getline(cin,myEmployee[i].role);
cout<<"Salary: ";
cin>>myEmployee[i].salary;
}
return;
}
Employee searchSalaryMax(Employee *myEmployee,int length){
int index=0;
double maxSalary=myEmployee[0].salary;
for(int i=1;i<length;i++){
if(myEmployee[i].salary>maxSalary){
maxSalary=myEmployee[i].salary;
index=i;
}
}
return myEmployee[index];
}
Employee searchSalaryMin(Employee *myEmployee,int length){
int index=0;
double minSalary=myEmployee[0].salary;
for(int i=1;i<length;i++){
if(myEmployee[i].salary<minSalary){
minSalary=myEmployee[i].salary;
index=i;
}
}
return myEmployee[index];
}
void display(Employee myEmployee){
cout<<"Name: "<<myEmployee.name<<endl;
cout<<"Day of birth: "<<myEmployee.birthDay.day<<"/"<<myEmployee.birthDay.month<<"/"<<myEmployee.birthDay.year<<endl;
cout<<"Role: "<<myEmployee.role<<endl;
cout<<"Salary: "<<myEmployee.salary<<endl;
return;
}
int main(){
//clrscr();
Employee *myEmployee,tempEmployee;
int length=0;
cout<<"Mount of employees: ";
cin>>length;
//khoi tao danh sach nhan vien
InitEmployee(myEmployee,length);
//nhan vien co luong cao nhat
tempEmployee=searchSalaryMax(myEmployee,length);
display(tempEmployee);
//nhan vien co luong thap nhat
tempEmployee=searchSalaryMin(myEmployee,length);
display(tempEmployee);
//giai phong vung nho
delete myEmployee;
return 0;
}