C++Geek wrote:[color=blue]
> I need to get this program to average the salaries. What am I doing
> wrong?[/color]
Well, for one thing, you're not asking a good question.
For one thing, you need to *tell* us what you expect and what's actually
happening.[color=blue]
>
>
>
>
> //Program to read in employee data and calculate the average salaries
> of the emplyees.
>
>
> #include <iostream>
> using namespace std;
>
> const int n =10;
>
>
> struct date
> {
> int month;
> int day;
> int year;
> }calendar;[/color]
What is purpose of having *one* of these?[color=blue]
>
> struct employee
> {
> char name[20];
>
>
>
>
> date HireDate;
> double salary;
> }EmpInfo;
>[/color]
Similarly.[color=blue]
> void employee_information(employee EmpInfo, date calendar);[/color]
`void' functions that take arguments by value tend to be suspect (unless
they only exist for their side effects; this will come up later).[color=blue]
>
> double average(employee emp[], int n);
>
> int main()
>
> {
> employee emp[n];
> int actual_emp;
>
>
> do
> {
> cout<<"Please enter the number of employees less than or = 10"<<endl;
> cin>>actual_emp;[/color]
You really should have error checking here -- but it's early in the
semester.
[color=blue]
> }
>
> while
>
> (actual_emp >= n);
>
>
>
> for(int employee=0; employee < actual_emp; employee++)
>
> employee_information(EmpInfo, calendar);[/color]
Somehow, I don't the above function call accomplishes what you want. In
fact, all it does is `fill' a pair of local structures that are copies
of the global (uninitialized) ones -- and throws them away!
[color=blue]
> average(emp, n);[/color]
When have you put anything into `emp'?[color=blue]
>
> cout<<employee++<<endl;[/color]
What is `employee' here? The loop variable above has gone out of scope..[color=blue]
> average(emp, n);[/color]
....and, in any event, what is the purpose of taking same `average' (in
quotes because it's working on an uninitialized array?[color=blue]
>
> return 0;
>
> }
>
> void employee_information(employee EmpInfo, date calendar)
>
> {
>
> cout<<"Please enter Employees name"<<endl;
> cin>>EmpInfo.name;
> cout<<"Please enter hire month"<<endl;
> cin>>EmpInfo.HireDate.month;
> cout<<"Please enter hire day"<<endl;
> cin>>EmpInfo.HireDate.day;
> cout<<"Please enter hire year"<<endl;
> cin>>EmpInfo.HireDate.year;
> cout<<"Please enter the emplyees salary"<<endl;
> cin>>EmpInfo.salary;
>
>
> cout<<"This employee was hired on "<<EmpInfo.HireDate.month<<" "
> <<EmpInfo.HireDate.day<<" in the year
> "<<EmpInfo.HireDate.year<<endl;
> cout<<"His current salary is $"<<EmpInfo.salary<<endl;
> }
>
> double average(employee emp[], int n)
>
> {
> int sum =0, actual_emp;
> sum = sum + EmpInfo.salary;
>
> cout<<sum/actual_emp;
>
> return 0 ;
> }
>[/color]
Answer the above questions for yourself and you'll be well on the way to
getting this program written.
HTH,
--ag
--
Artie Gold -- Austin, Texas
http://goldsays.blogspot.com http://www.cafepress.com/goldsays
"If you have nothing to hide, you're not trying!"