How can I make this function work?

Ok so I have the function declared at the top before main
 
void read_data (string firsts [], string lasts [], int ages [], int total);

I also have the function definition at the bottom after main
1
2
3
4
5
6
7
8
9
10
11
12
void read_data (string firsts [], string lasts [], int ages [], int total)
{
	cout << "Enter the number of data items: " << endl;
	cin >> total;
	int i;
	for (i = 0; i<=total; i++)
	{
	cout << "Enter first name, last name, and age: " << endl;
	cin>>firsts[i]>>lasts[i]>>ages[i];
	
	}
}

Then I tried to call the function in main but I don't know how to make it work what I have so far is this
 
read_data(firsts, lasts, ages, total);

I know I need to declare firsts, lasts, ages and total in main but I don't know how.
what are you trying to accomplish other than making that function run?
It is a part of a program and I have everything else I just need to know how to call the function in main.. I mean I did call it but I just need to know how to declare firsts, lasts, ages and total so that the function can run properly
can you post all of your code.
closed account (D80DSL3A)
You're passing 3 arrays and an integer.
Can you anticipate a maximum size for the arrays?
Not sure why you're passing a value for the total when you're just going to overwrite it in the function. Perhaps you intend to have a variable in main keep the value entered by the user? In this case you'll need to pass total by reference, not value. ie:
void read_data (string firsts [], string lasts [], int ages [], int& total);// note the '&' before total

Adjust the array maxSize accordingly:
1
2
3
4
5
6
7
const int maxSize = 50;
string firsts[maxSize];
string lasts[maxSize];
int ages[maxSize];
int total = 0;

read_data (firsts, lasts, ages, total);// total will have the value entered in the function. 
Thanks it worked this is exactly what I needed to do!
Topic archived. No new replies allowed.