How do i make this a function?

Currently working on a project that is supposed to create an insert sort linked list, then through an option in a switch function, return the list. Here's what I have so far, option 'I' is to insert new entries, and option 'S' needs to display the list:
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#include "stdafx.h"
#include <iostream>
#include <string>
#include <cstring>
#include <iomanip>

using namespace std;

struct student
{
	string name, addr, en_day, en_month, en_year, c_day, c_month, c_year;
	student *next;
};

int dateFinder(int, int, int);
void titlePage();
void exitPage();
void pageHeader();
void invalid();
void main_menu();
//----------------------------- new prototypes
student *insert(student*, student*);
void printList(student*);
void outPut(student*);
student makeList();


int _tmain(int argc, _TCHAR* argv[])
{
	titlePage();
	main_menu();
	return 0;
}

void main_menu()																				// Main Menu function
{
	string optionSelected;	
	string sResults = "Search Results: No results could be found! A new profile has been created... \n";
	string mainMenu = "--Main Menu--";																
	string entryOption = "To create a new entry, press 'I'";	
	string displayOption = "To view sorted student list, press 'S'";
	string searchOption = "To search for a student record, please press 'E'";
	string printOption = "To create a TXT file of the student record, press 'P'";
	string quitOption = "To exit the program, please press 'Q'";
	

	do																											// Begin Main Menu
	{
		system("cls");
		pageHeader();

		cout << endl;																							// Begin Body
		cout << endl;
		cout << endl;
		cout << setw(((80 - mainMenu.length()) / 2) + mainMenu.length()) << mainMenu << endl;					// Display mainMenu string in center 
		cout << endl;
		cout << endl;
		cout << setw(((80 - entryOption.length()) / 2) + entryOption.length()) << entryOption << endl;			// Display searchOption string in center
		cout << setw(((80 - displayOption.length()) / 2) + displayOption.length()) << displayOption << endl;	// Display displayOption string in center
		cout << setw(((80 - searchOption.length()) / 2) + searchOption.length()) << searchOption << endl;		// Display searchOption string in center
		cout << setw(((80 - printOption.length()) / 2) + printOption.length()) << printOption << endl;
		cout << setw(((80 - quitOption.length()) / 2) + quitOption.length()) << quitOption << endl;				// Display quitOption string in center
		cout << endl;
		cout << endl;

		cin >> optionSelected;											// Get Menu Option

		switch(tolower(optionSelected.at(0)))
		{
			case 'i':													// Input Student info
				makeList();
				break;
		
			case 's':													// Sort and display student entries
				printList(list);
				break;

			case 'e':													// Search for an entry
				break;

			case 'p':													// sort entries and print to .prn file
				break;

			case 'q':													// Quit, ends do loop
				break;

		default:														// Invalid Entry
		{
			cin.get();	
			invalid();
		}
			break;
		}
	}
	while((optionSelected.at(0) != 'q') && (optionSelected.at(0) != 'Q'));							// While optionSelected is not Q, execute do loop
	exitPage();																						// Exit Pate
	cin.get();
}

student makeList()
{
	student *p, *q, *list = NULL;
	string ans = "Y";

	while(toupper(ans.at(0)) == 'Y')
	{
		system("cls");
		p = new student;
		if(p == NULL)
		{
			cout << "Error, out of memory" << endl;
			cin.get();
			exit(0);
		}
		else 
		{
			cout << " Enter a name: "; getline(cin, p-> name);
			p -> next = NULL;

			q = insert(p, list);
			if(q == NULL)
			{
				p -> next = list;
				list = p;
			}
			else
			{
				p -> next = q -> next;
				q -> next = p;
			}
		}
		cout << "Enter another record?(Y/N) "; getline(cin, ans);
	}
	return *list;
}
student* insert(student* newItem, student* first)
{
	student *trailer = NULL;

	while((first != NULL) && (first -> name < newItem -> name))
	{
		trailer = first;
		first = first -> next;
	}

	return trailer;
}

void printList(student* first)
{
	int ctr = 0;
	cout << "**** List ****" << endl;
	for(; first != NULL; first = first -> next)
	{
		cout << ctr + 1 << " " << setw(10) << first -> name << endl;
		ctr++;
	}
	cin.get();
	cin.get();
}


Thanks ahead for any input :)
Topic archived. No new replies allowed.