I am trying to right a program where I consider a Employee with data:
age
(an integer),
id
(an integer),
salary
(a float). I want to create three one-dimensional arrays with length 3. Then I would want cout asking for the input values for the elements and use cin to grab users' input from keyboard. Next, pass the three arrays to a function, PrintEmployee(arg1, arg2, arg3, arg4), in which arg1 through arg3 should be the arrays of Employee and arg4 is the length of the array (=3 in this case). In PrinteEmployee(arg1,arg2, arg3, arg4). Im trying to right a for loop to prnt out the information of each employee. And I also want to print avg salary and avg age. I really need help!! Here is my code so far:
#include "stdafx.h"
#include <string>
#include <iostream>
using namespace std;
void main()
{
int Age [3];
int Id [3]; //create an array of Employee with three elements
float Salary [3];
cout << "What is the employee Age, Id number,and Salary:"; //ask user from keyboard for each element
cin>>Age
cin>>Id
cin>>Salary
Age [0] = 30; // set values for the three elements
Age [1] = 30042554;
Age [2] = 50000.00;
Id [0] = 45;
Id [1] = 40041002;
Id [2] = 70000.00;
PrintEmployee(Age,Id,Salary); //call PrintEmployee() with a proper paramater list
}
void PrintEmployee(int a[], int b[], float c[])
{
for (int i=0;i<3;i++) //for loop
{
int AvgSalary = float c [0]+float c [1]+float c[2]/3;
int AvgAge = int a[0] + int a[1] + int a[2]/3;
cout<<a[i]<<"Employee 1: "<<int a[0],int b[0],float c[0]<<endl;//Output the information to screen by calling the member functions of the struct
cout<<b[i]<<"Employee 2: "<<int a[1],int b[1],float c[1]<<endl;
cout<<c[i]<<"Employee 3: "<<int a[2],int b[2],float c[2]<<endl;
cout<<"Average Salary: "<<AvgSalary<<endl;//Print out the average salary
cout<<"Average Age: "<<AvgAge<<endl; //print out the average age
}
It probably totally wrong but I need help at least getting on the right track.
Because it is the end of the program and the console "disappears" in the very moment. So, cin.get() will wait for you press the return key. This is for the windows platform. No need for the Linux platform this "trick".