passing arrays to functions

I would like to pass the seats array to the void function but i have only learned how to pass constants to a function. How do you pass an array to a function?

This was my attempt but I have run into many errors. Can anyone help?
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
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;


void display_final_seating(int);



int main()
{
	const int unoccupiedSeat = -1, num_passengers = 100;
	int seats[num_passengers];


	for(int i = 0; i < num_passengers; i++)
		seats[i] = unoccupiedSeat;




	display_final_seating(seats[num_passengers]);


	cout << endl;
	return 0;
}


void display_final_seating(int seats[100])
{	
	for(int i = 5; i <= 95; i+=6)
		cout << seats[i] << " ";
	cout << endl;
	for(int i = 4; i <= 94; i+=6)
		cout << seats[i] << " ";
	cout << endl;
	for(int i = 3; i <= 99; i+=6)
		cout << seats[i] << " ";
	cout << endl;
	for(int i = 2; i <= 98; i+=6)
		cout << seats[i] << " ";
	cout << endl;
	for(int i = 1; i <= 97; i+=6)
		cout << seats[i] << " ";
	cout << endl;
	for(int i = 0; i <= 96; i+=6)
		cout << seats[i] << " ";
	cout << endl;
}
I see only two errors right of. In your prototype, use int[] as the type you are passing.And on line 23, simply pass seats. When you write seats[num_passengers] that is trying to get a particular element of the array, which also happens to be out of bounds.
Thanks very much! It works without errors now!
Topic archived. No new replies allowed.