Expected Initializer before 'COORD'

There is an error and i cannot figure it out
the error is in the code
can you please provide a fix, that would be great
thanks

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
#include <iostream>
#include <Windows.h>
#include <string>
#include <stdio.h>
#include <conio.h>

using namespace std;

int main ()
{
	int choice;

	label:
	
	cout << "Welcome to the menu";
	cout << "Please choose a program" << "\n\n";
	
	cout << "1. Do while loop" << "\n\n";
	cout << "2. For loop" << "\n\n";
	cout << "3. While loop" << "\n\n";
	cout << "4. Gradenator" << "\n\n";
	cout << "5. Gotoxy" << "\n\n";
	cout << "\n\n";
	cout << "Your choice here: ";
	cin >> choice;
	cout << "\n\n";

	switch (choice)
	{
		case 1:
			cout << "Please wait...";
			cin.get();
			system ("cls");
			
			{
				int x;
	
				x = 4;
				do	{
				x++;
				cout << x << "\n";
	 			} while (x > 2);
				cin.get ();
			}
			break;
			
		case 2:
			cout << "Please wait...";
			system ("cls");
			
			{
				for (int x = 1; x < 10; x *= 2)
				{
					Sleep (100);
					cout << x << endl;
				}	
				cin.get ();
			}
			
			cout << "\n\n";
			cout << "Press enter to exit";
			cin.get (); 
			system ("cls");
			goto label;
			
		case 3: 
			cout << "Please wait...";
			system ("cls");
			
			{
				int x = 1;
	
				while (x < 10)
				{
					cout << x << endl;
					x++;
					Sleep (100);
				}
				cin.get ();
			}
		
			cout << "\n\n";
			cout << "Press enter to exit";
			cin.get (); 
			system ("cls");
			goto label;
			
		case 4:
			cout << "Please wait...";
			system ("cls");
			
			{
				int mark, total;
				float percent;
	
				cout.setf(ios::fixed);
				cout.precision(1);
	
				system ("cls");
				cout << "What mark did you get? ";
				cin >> mark;
				cout.width(23); cout << "What was it out of? ";
				cin >> total;
				percent = mark * 100.0 / total;
				cout << "\nYour mark is " << percent << "%";
	
				cout.width(30); cout<< "Goodbye!!\n\n";
				cin.get(); 
			}
			
			cout << "\n\n";
			cout << "Press enter to exit";
			cin.get (); 
			system ("cls");
			goto label;
			
		case 5:
			cout << "Please wait...";
			system ("cls");
			
			void gotoxy (int x, int y) 
			{
				COORD coord;	// expected initializer befor 'COORD'
				coord.X = x;
				coord.Y = y;
				SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
			}

			int main ()
			{
				gotoxy(80, 1);
				cout << "I am over here!!!";
				getch ();
				return (0);
			}
			
	}
}
Last edited on
You have 2 main() functions, 1 of them is embedded inside the other, that needs to be fixed. Also your gotoxy() func is embedded in a main() and needs to be its own function.

I'm guessing the you forgot 2 "}"s (1 to conclude the switch, 1 to conclude body of the main() that starts on line 9) around line 120.
btw, don't use goto
I dont understand can you please show me how to fix it
Thanks
I mean it would look more like this:
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
void MyFunction()
{
	int choice;

	label:
	
	cout << "Welcome to the menu";
	cout << "Please choose a program" << "\n\n";
	
	cout << "1. Do while loop" << "\n\n";
	cout << "2. For loop" << "\n\n";
	cout << "3. While loop" << "\n\n";
	cout << "4. Gradenator" << "\n\n";
	cout << "5. Gotoxy" << "\n\n";
	cout << "\n\n";
	cout << "Your choice here: ";
	cin >> choice;
	cout << "\n\n";

	switch (choice)
	{
		case 1:
			cout << "Please wait...";
			cin.get();
			system ("cls");
			
			{
				int x;
	
				x = 4;
				do	{
				x++;
				cout << x << "\n";
	 			} while (x > 2);
				cin.get ();
			}
			break;
			
		case 2:
			cout << "Please wait...";
			system ("cls");
			
			{
				for (int x = 1; x < 10; x *= 2)
				{
					Sleep (100);
					cout << x << endl;
				}	
				cin.get ();
			}
			
			cout << "\n\n";
			cout << "Press enter to exit";
			cin.get (); 
			system ("cls");
			goto label;
			
		case 3: 
			cout << "Please wait...";
			system ("cls");
			
			{
				int x = 1;
	
				while (x < 10)
				{
					cout << x << endl;
					x++;
					Sleep (100);
				}
				cin.get ();
			}
		
			cout << "\n\n";
			cout << "Press enter to exit";
			cin.get (); 
			system ("cls");
			goto label;
			
		case 4:
			cout << "Please wait...";
			system ("cls");
			
			{
				int mark, total;
				float percent;
	
				cout.setf(ios::fixed);
				cout.precision(1);
	
				system ("cls");
				cout << "What mark did you get? ";
				cin >> mark;
				cout.width(23); cout << "What was it out of? ";
				cin >> total;
				percent = mark * 100.0 / total;
				cout << "\nYour mark is " << percent << "%";
	
				cout.width(30); cout<< "Goodbye!!\n\n";
				cin.get(); 
			}
			
			cout << "\n\n";
			cout << "Press enter to exit";
			cin.get (); 
			system ("cls");
			goto label;
			
		case 5:
			cout << "Please wait...";
			system ("cls");
               }  //END switch()
}  //END this function body.

//Below is a new function entirely, so it needs to be outside all other funcs.
void gotoxy(int x, int y) 
{
   COORD coord;	
   coord.X = x;
   coord.Y = y;
   SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}

int main ()  //This is your "real" main function...
{
   gotoxy(80, 1);
   cout << "I am over here!!!";

   //I'm guessing you meant to have this here...
   MyFunction();

   getch ();
   return (0);
}


I'd also recommend moving the "cout << "Please wait..."; system("cls");" to right before your switch() statement, because it occurs in every one of your case labels.

And the code in your "case 1" section is not right. X starts at 4, so your loop will execute again and again (b/c 4 id > 2, and X gets increased each iteration) until it reaches the maximum possible value for an "int" which is system-specific but typically (2 ^ 32) - 1. After that iteration anything can happen happen b/c signed integer overflow is undefined.
Last edited on
Thank you so much
You helped a lot!
Also, it's good practice to have a default in a switch statement. If a user entered 6 during the MyFunction function, the program would crash
Topic archived. No new replies allowed.