struct function

Dec 11, 2015 at 11:05pm
I have spent so many hours trying to make this work and I just can't seem to get it right.
This is the part that I am having trouble with: Write a void function called display() to display each element of the struct at the end of the program, call display and pass it the array of structs.



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
void display(Leads names[], size_t num_elements)
{
	char answerTwo;

	cout << "Would you like to see only active leads? y or n?" << endl;
	cin >> answerTwo;

	if (answerTwo == 'y')
	{
		for (int i = 0; i < 3; i++)
		{
			if (x.active == true)
			{
				cout << x.name;
				cout << x.budget;
			}
		}
	}
	else if (answerTwo == 'n')
	{
		cout << x.name;
		cout << x.budget;
	}
}
Last edited on Dec 12, 2015 at 7:58pm
Dec 11, 2015 at 11:37pm
Write a void function called display() to display each element of the struct at the end of the program, call display and pass it the array of structs.



void display(Leads x, Leads names);
In the above snippet you are passing two single Leads, not an array of Leads. You really should be passing an array, along with the number of elements in that array.

void dispaly(Leads names[], size_t num_elements);

You'll need to change the implementation and the function call to reflect this change.
Dec 12, 2015 at 12:47am
Thank you! I had a feeling that I had that wrong.
But now how would I be able to use cout << x.name, etc; or is that not necessary?
Last edited on Dec 12, 2015 at 12:51am
Dec 12, 2015 at 4:16am
If you're talking about your display() function, where did you declare a variable named x?

That function is using an array of Leads called names. This is the variable you will use. You need to restructure the program to take the changes you made to the function signature into account.
Topic archived. No new replies allowed.