PLEASE HELP

so i have a home work on structs and i made this code , i just cant figure out where i went wrong
the cin isnt filling my array and its giving me a garbage value



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
struct companyType 
{
string CompName,PhoneNumber ;   
int EstablishmentYear,ImployeeCount;
double ImployeeSalaries [2];
};
void Read(companyType comp)
{
	cout<<"Please fill the 2 salaries: "<<endl;
	for (int i=0;i<2;i++)
		cin>> comp.ImployeeSalaries[i];
}
void Print(companyType comp)
{
	cout<<"The company name is : "<<comp.CompName<<endl<<"Phone number: "<<comp.PhoneNumber<<endl;
	cout<<"Establishment year: "<<comp.EstablishmentYear<<endl<<"Numbers of employees: "<<comp.ImployeeCount<<endl;
	for( int i=0;i<2;i++)
		cout<<comp.ImployeeSalaries[i]<<"\t";
	cout<<endl;
}
double SalariesAvg(companyType comp)
{
	double avg=0;
for (int i=0;i<10;i++)
	avg+=comp.ImployeeSalaries[i];
avg/=10;

	return avg;
}
void main ()
{
	companyType comp;
	comp.CompName="CompuBase";
	comp.PhoneNumber="7575771";
	comp.EstablishmentYear=1998 ;
	comp.ImployeeCount=10;
	Read(comp);
	Print (comp);
	cout<<"The salary average is : "<<SalariesAvg(comp);

}
The mistake was to pass comp to Read by value, instead of by reference. Now Read writes things to a copy of comp which does not change the original. The solution is to change read to void Read(companyType& comp). Do read something about passing by value and by reference.
THANK YOU!!!
Topic archived. No new replies allowed.