#include <iostream.h>
struct EmpRec {
char empCode[5];
char empname[20];
int age;
float salary;
int yearJoined;
};
int GiveCars(struct EmpRec Emp[10],int NumOfEmp);
int main(){
struct EmpRec Emp[10];
int NumOfEmp,count=0;
cout<<"Please enter the number the records to be kept(max=10) : ";
cin>>NumOfEmp;
while(count<NumOfEmp){
cout<<"Employee Code : ";
cin>>Emp[count].empCode;
cout<<"Employee Name : ";
cin>>Emp[count].empname;
cout<<"Employee Age : ";
cin>>Emp[count].age;
cout<<"Employee Salary : ";
cin>>Emp[count].salary;
cout<<"Year Joined : ";
cin>>Emp[count].yearJoined;
cout<<"---------------------------------"<<endl;
count++;
}
cout<<"The numbers of employee entitled for the car : "<<GiveCars(struct EmpRec Emp,NumOfEmp)<<endl;
return 0;
}
int GiveCars(struct EmpRec Emp[10],int NumOfEmp){
int count=0,entitled=0,totalyear;
while(count<=NumOfEmp){
totalyear=2010-Emp[count].yearJoined;
if (totalyear>10 )
entitled++;
else
;
count++;
}
return entitled;
}
Error Message:
C:\Documents and Settings\XPMUser\Desktop\Cpp1.cpp(38) : error C2144: syntax error : missing ')' before type 'EmpRec'
C:\Documents and Settings\XPMUser\Desktop\Cpp1.cpp(38) : error C2660: 'GiveCars' : function does not take 0 parameters
C:\Documents and Settings\XPMUser\Desktop\Cpp1.cpp(38) : error C2059: syntax error : ')'
btw....
After the input you just assume that the person typing the number of employees actually puts a number less than 10... You should check again in your program....
After the std::cin either put a
1 2 3
if (NumOfEmp > 10) {
NumOfEmp = 10;
}
Or ask again if the NumOfEmp is bigger than 10....
Same thing about the name and code...
You might want to look at something like std::vector or std::list... and for the char arrays std::strings ;-) good luck