Need help compiling

I wrote a code for a program that asks the user for a input file and takes the information from the file and sorts it. It then calculates the average and median. it puts all of the stuff in a file called occupations.out. this is my code:

#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
using namespace std;
const int MAX_OCCUPATIONS = 10;


bool openFile(ifstream&);
void sortOccupations(ifstream&);
double calcSalaries(double salary);
void printSalaries( double average, double median);

int main()
{
string input_file, occupations; // input file and occupations
string countries[1]; // input file and country names
double salary[MAX_OCCUPATIONS]; // number of occupations
sort(num_occupations);
ifstream input;

while ( openFile ( input ) )
{
sortOccupations ( input );
}
if (input.fail() )
{
cout << “Input file “ << input_file << “does not exist”;
}
else
calcSalaries ( input );
printSalaries ( input );
return ( 0 );
}

/* openFile: prompts user for input file, 3 tries
Parameters:
input: ifstream object (input file)
Returns: true if input file is successfully opened
*/
bool openFile(ifstream&)
{
string input_file; // the input file used to get the data
int attempts = 0; // number of tries ti open the file

// prompt for input file
cout << “Enter the name of the input file\n”;
cin >> input_file;
input.open( input_file );
attempts++;

while ( input.fail() && attempts < 3 )
{
cout << “Could not open file. Enter the name of the input file\n”;
cin >> input_file;
input.open( input_file );
attempts++;
}
if ( input.fail() )
{
return false;
}
}

/* sortOccupations: sorts the occupations into a table
Pre-conditions:
The input file was opened successfully
Parameters:
input: ifstream object (input file)
Returns: Nothing
*/
void sortOccupations(ifstream&)
{
double salary;
string occupations
int index_of_next_smallest;
for ( int index = 0; index < number_used - 1; index++)
index_of_next_smallest = index_of_smallest(a, index, number_used);
swap_values(a[index], a[index_of_next_smallest]);

//set precision
cout.setf( ios::fixed | ios::showpoint );
cout.precision( 2 );

cout << “Occupations Salary\n”;
cout << “____________________\n”;
cin >> occupations >> salary;
while ( !in.eof() )
{
cout << setw(19) << occupation << “ $” << setw(10) << salary << endl;
cin >> occupation >> salary;
}
cout << endl;
}

/* calcSalaries: calculates the median and the average of the salaries
Pre-conditions:
The input file was opened successfully.
Parameters:
salary: used to calculate average and median
Returns: Average and median of salaries
*/
double calcSalaries(double salary)
{
double salary[MAX_OCCUPATIONS];
double sum;
double average;
double median;
int n, total = 0;

for (int i=0, i < 9, i++)
{
total = total + salary[i];
}
average = total / salary;

if(n%2 == 0)
{
int middle = n / 2;
int middle1 = (n / 2)-1;
median = (salary[middle] + salary[middle1]) / 2;
}
return average, median;

/* printSalaries: Prints out the average and median into occupations.out
Pre-conditions:
Input file was opened succesfully
Parameters:
average: average of salaries
median: median of salaries
Returns: Nothing
*/
void printSalaries( double average, double median )
{
// write to output file
output.open( “occupations.out” );
output << “Average salary: $ ” << average << endl;
output << “Median salary: $ “ << median << endl;
output.close ( );
return(0);
}

It does not compile. I need help please.
Please use code tags and also state you errors.

Aceix.
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
using namespace std;
const int MAX_OCCUPATIONS = 10;


bool openFile(ifstream&);
void sortOccupations(ifstream&);
double calcSalaries(double salary);
void printSalaries( double average, double median); 

int main()
{
	string input_file, occupations;   // input file and occupations
string countries[1];  // input file and country names
	double salary[MAX_OCCUPATIONS];   // number of occupations
	sort(num_occupations);
	ifstream input;
	
while ( openFile ( input ) )
{
	sortOccupations ( input );
}
if (input.fail() )
{
	cout << “Input file “ << input_file << “does not exist”;
}
else
	calcSalaries ( input );
	printSalaries ( input );
return ( 0 );
}

/* openFile: prompts user for input file, 3 tries
   Parameters: 
input: ifstream object (input file)
   Returns: true if input file is successfully opened
*/
bool openFile(ifstream&)
{
	string input_file;  // the input file used to get the data
	int attempts = 0;    // number of tries ti open the file

	// prompt for input file
	cout << “Enter the name of the input file\n”;
	cin >> input_file;
	input.open( input_file );
	attempts++;

	while ( input.fail() && attempts < 3 )
	{
		cout << “Could not open file. Enter the name of the input file\n”;
		cin >> input_file;
		input.open( input_file );
		attempts++;
	}
	if ( input.fail() )
	{
		return false;
	}
}

/* sortOccupations: sorts the occupations into a table
   Pre-conditions:
	The input file was opened successfully
   Parameters:
	input: ifstream object (input file)
   Returns: Nothing
*/
void sortOccupations(ifstream&)
{
	double salary;
	string occupations
int index_of_next_smallest;
for ( int index = 0; index < number_used - 1; index++)
index_of_next_smallest = index_of_smallest(a, index, number_used);
swap_values(a[index], a[index_of_next_smallest]);

//set precision
cout.setf( ios::fixed | ios::showpoint );
cout.precision( 2 );

cout << “Occupations                Salary\n”;
cout << “____________________\n”;
cin >> occupations >> salary;
while ( !in.eof() )
{
	cout << setw(19) << occupation << “     $” << setw(10) << salary << endl;
	cin >> occupation >> salary;
}
cout << endl;
}

/* calcSalaries: calculates the median and the average of the salaries
   Pre-conditions:
	The input file was opened successfully.
   Parameters:
	salary: used to calculate average and median
   Returns: Average and median of salaries
*/
double calcSalaries(double salary)
{
	double salary[MAX_OCCUPATIONS];
double sum;
	double average;
	double median;
	int n, total = 0;
	
	for (int i=0, i < 9, i++)
	{
		total = total + salary[i];
	}
	average = total / salary;

	if(n%2 == 0)
	{
		int middle = n / 2;
		int middle1 = (n / 2)-1;
		median = (salary[middle] + salary[middle1]) / 2;
	}
	return average, median;

/* printSalaries: Prints out the average and median into occupations.out
   Pre-conditions:
	Input file was opened succesfully
   Parameters:
	average: average of salaries
	median: median of salaries
   Returns: Nothing
*/
void printSalaries( double average, double median )
{
// write to output file
output.open( “occupations.out” );
output << “Average salary:  $ ” << average << endl;
output << “Median salary:  $ “ << median << endl;	
	output.close ( );
	return(0);
}

the errors are:

lab5.cpp: In function 'int main()':
lab5.cpp:37: error: cannot convert 'double*' to 'double' for argument '1' to 'double calcSalaries(double)'
lab5.cpp:38: error: cannot convert 'double*' to 'double' for argument '1' to 'void printSalaries(double, double)'
lab5.cpp: In function 'bool openFile(std::ifstream&)':
lab5.cpp:56: error: 'input' was not declared in this scope
lab5.cpp: In function 'void sortOccupations(std::ifstream&)':
lab5.cpp:86: error: 'number_used' was not declared in this scope
lab5.cpp:87: error: 'a' was not declared in this scope
lab5.cpp:87: error: 'index_of_smallest' was not declared in this scope
lab5.cpp:88: error: 'a' was not declared in this scope
lab5.cpp:88: warning: name lookup of 'index' changed
<built-in>:0: warning: matches this 'char* index(const char*, int)' under ISO standard rules
lab5.cpp:86: warning: matches this 'index' under old rules
lab5.cpp:88: error: 'swap_values' was not declared in this scope
lab5.cpp:97: error: 'in' was not declared in this scope
lab5.cpp:99: error: 'occupation' was not declared in this scope
lab5.cpp: In function 'double calcSalaries(double)':
lab5.cpp:115: error: declaration of 'double salary [10]' shadows a parameter
lab5.cpp:119: error: conflicting declaration 'int total'
lab5.cpp:116: error: 'total' has a previous declaration as 'double total'
lab5.cpp:121: error: expected initializer before '<' token
lab5.cpp:125: error: invalid operands of types 'double' and 'double [10]' to binary 'operator/'
lab5.cpp:127: error: expected primary-expression before 'if'
lab5.cpp:127: error: expected ')' before 'if'
lab5.cpp: In function 'void printSalaries(double, double)':
lab5.cpp:146: error: declaration of 'double average' shadows a parameter
lab5.cpp:147: error: declaration of 'double median' shadows a parameter
lab5.cpp:150: error: 'output' was not declared in this scope
lab5.cpp:154: error: return-statement with a value, in function returning 'void'
Topic archived. No new replies allowed.