PROBLEM WITH STRUCT FUNCTION

Write your question here.
Why is my program stuck at line 59?

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
/*
*	Chapter 11 Problem 3
*
*	Create an address book problem that builds on problem 1 - this
*	time, the user should be able to not just fill in a single structure
*	but should be able to add new entries as he or she wants - is this easy
*	to do?  Is it even possible?  Add the ability to display all or some of 
*	the entries, letting the user browse the list of entries.
*
*	Define structure
*	Let user add 5 entries if more required, make array bigger
*	Display menu to add entry, display entries, display a single entry, quit
*
*/

#include <iostream>
#include <string>

using namespace std;

// Function prototypes
AddressBook AddEntry(AddressBook array[], int index_entries);
AddressBook DisplayEntry(AddressBook array[], int size);


struct AddressBook
{
	string name;
	string address;
	string phone;
};

int main()
{
	// Declare and intialize variables
	AddressBook person[20];
	int size = 1;
	int choice = 0;
	int count = 0;

	// Display Menu
	cout << "Menu:" << endl <<
		'\t' << "0. Quit" << endl <<
		'\t' << "1. Add an entry" << endl <<
		'\t' << "2. Display an entry" << endl <<
		'\t' << "3. Display all entries" << endl <<
		'\t' << "4. Display a range of entries" << endl;

	cout << "Please make a selection: ";
	cin >> choice;

	switch (choice)
	{
	case 0:
		return 0;
		break;
	case 1:
		cout << "Index is currently at: " << count << endl;
		person[count] = AddEntry(person, count);
		count++;
		break;
	case 2:
		break;
	case 3:
		break;
	case 4:
		break;
	}
}


AddressBook AddEntry(AddressBook array[], int index_entries)
{
	cout << "Please enter your full name: ";
	getline(cin, array[index_entries].name);

	cout << "Please enter your address: ";
	getline(cin, array[index_entries].address);
	 
	cout << "Please enter your phone number: ";
	getline(cin, array[index_entries].phone);

	return array[index_entries];
}


AddressBook DisplayEntry(AddressBook array[], int index_entries)
{
	cout << array[index_entries].name << endl;
	cout << array[index_entries].address << endl;
	cout << array[index_entries].phone << endl;
} 
Thank you.

I found that the struct should be before declaring the function prototype as I was still working on the program after I posted it. The return value in the DisplayEntry function was found earlier, but I guess I did not incorporate.

Thank you again.
You welcome.
Topic archived. No new replies allowed.