Errors in my code.

Good day people. I have problem here where i got several errors i got is
error C2601: 'systemExit' : local function definitions are illegal
error C2601: 'addVehicle' : local function definitions are illegal
error C2601: 'sortVehicle' : local function definitions are illegal
error C2601: 'deleteVehicle' : local function definitions are illegal
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
  #include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
#include <list>
using namespace std;
	string type[20];
	int RegNo[20];
	string model[20];
	float tax[30];
	int count;
	void addVehicle();
	void deleteVehicle();
	void sortVehicle();
	void findVehicle();
	void systemExit();
	void main()
	{
		int menu;
		do
		{
			cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
			cout << "\tWelcome to My Family Vehicles Program\n";
			cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
			cout << "\t[1]\tAdd new vehicle\n";
			cout << "\t[2]\tRemove a vehicle\n";
			cout << "\t[3]\tView all vehicle\n";
			cout << "\t[4]\tFind a vehicle\n";
			cout << "\t[5]\tExit\n";
			cin >> menu;
			cin.ignore(numeric_limits <streamsize> ::max(), '\n');
			switch (menu)
			{
			case 1:
			{
				addVehicle();
				system("PAUSE");
			}
			case 2:
			{
				deleteVehicle();
				system("PAUSE");
			}
			case 3:
			{
				sortVehicle();
				system("PAUSE");
			}
			case 4:
			{
				findVehicle();
				system("PAUSE");
			}
			case 5:
			{
				systemExit();
				system("PAUSE");
			}
			}
		} while (1);
		void addVehicle();
		{
			int i;
			cout << "Add new vehicle: \n";
			if (i < 5)
			{
				cout << "You have choose to add new vehicle and please fill up the requirement needed: \n";
				cout << "Type of vehicle (Car/Motorcycle/MPV): ";
				getline(cin, type[i]);
				cout << "Car Registration number (Plate No.): ";
				cin >> RegNo[i];
				cout << "Car Model and Manufacutre: ";
				getline(cin, model[i]);
				cout << "Road Tax expiry date: ";
				cin.ignore(numeric_limits<streamsize>::max(), '\n');
				cin >> tax[i];
				cout << endl;
				i++;
			}
			else cout << "Invalid input. Please try again." << endl;
		}
		void deleteVehicle()
		{
			int i, del = 0;
			for (i = 0; i < count; i++)
			{
				cout << "You have selected to remove a vehicle.";
				cout << "Vehicle: " << i + 1 << ' ' << type[i] << ' ' << RegNo[i] << ' ' << model[i] << ' ' << tax[i] << ' ' << endl;
			}
			cout << "Please enter name of vehicle you wish to remove <delete>: " << endl;
			cin >> del;
			for (i = del; i < count - 1; i++)
			{
				type[i] = type[i + 1];
				RegNo[i] = RegNo[i + 1];
				model[i] = model[i + 1];
				tax[i] = tax[i + 1];
			}
			type[i] = " ";
			RegNo[i] = " ";
			model[i] = " ";
			tax[i] = " ";
			for (i = 0; i < count; i--)
			{
				cout << "Vehicle: " << i << ' ' << type[i] << ' ' << RegNo[i] << ' ' << model[i] << ' ' << tax[i] << ' ' << endl;
				cout << endl;
			}
			count--;
		}
		void sortVehicle()
		{
			int i, j;
			float temp4;
			string temp1, temp2, temp3;
			for (i = 0; i < count; i++)
			{
				for (j = i; j < count; j++)
				{
					if (strcmp(type[i].c_str(), type[j].c_str()) == 1)
					{
						temp1 = type[i];
						type[i] = type[i];
						type[j] = temp1;

						temp2 = RegNo[i];
						RegNo[i] = RegNo[j];
						RegNo[j] = temp2;

						temp3 = model[i];
						model[i] = model[j];
						model[j] = temp3;
					}
				}
			}
			for (i = 0; i < count; i++)
			{
				cout << type[i] << ' ';
				cout << RegNo[i] << ' ';
				cout << model[i] << ' ';
				cout << tax[i] << ' ';
			}
		}
		void findVehicle()
		{
			int i, j = 0;
			string search;
			cout << "Please enter the name of vehicle you wish to find. " << endl;
			cin >> search;
			for (i = 0; i < count; i++)
			{
				if (strcmp(type[i].c_str(), search.c_str()) == 0)
				{
					cout << "Type: " << type[i];
					cout << "RegNo: " << RegNo[i];
					cout << "Model: " << model[i];
					cout << "tax: " << tax[i];
					j++;
					system("PAUSE");
				}
			}
			if (j == 0)
				cout << "The entered name was not traceable in system. Please try again." << endl;
		}
		void systemExit()
		{
			char option;
			cout << "Do you wish to exit from system? Press <Y> for yes and <N> for no." << endl;
			cin >> option;
			if (option == 'Y')
				exit(0);
			else if (option == 'N')
				menu();
			else
				cout << "Invalid input. Please key in right key." << endl;
		}


You get the error messages because you are trying to define functions inside the main function. Functions are not allowed to be defined inside other functions. You should put the function definitions outside of main.
Last edited on
Peter87


Good day sir. Could you give an example of how it should be. So that i can get an clear idea on it .
At the moment you have it like this.
1
2
3
4
5
6
7
8
9
int otherFunction(); // function declaration

int main()
{
	int otherFunction() // function definition
	{
		// ...
	}
}

You should do it like this instead.
1
2
3
4
5
6
7
8
9
10
11
int otherFunction(); // function declaration

int main()
{
	
}

int otherFunction() // function definition
{
	// ...
}

Peter87


Sir, do you mean like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
int addVehicle();

int main()

{

        // . . .

}

int addVehicles()

{
       // . . .
}
Last edited on
Yes, but this is just so that you get the idea. The dots have to be replaced by code.

In your original post, maybe you just forgot to put an end to the main function using } before you defined addVehicle(). Also note that a function definition should not have a semicolon after the parentheses.

This is wrong
1
2
3
4
void addVehicle();
{
	// ...
}

This is right
1
2
3
4
void addVehicle()
{
	// ...
}
Last edited on
Peter87
Thank you sir. Much appreciate it. :)
Topic archived. No new replies allowed.