solved  my switch wont do its cases but it does with default??

jcylam (104)   Link to this post
1
2
3
4
5
6
7
8
9
10
11
12
13
14
	switch (*pclick_function)
	{
	case 1:
			Left_click_once (*pGT_X, *pGT_Y);
			cout << "\tLeft clicked\r";
			break;
	case 2:
			Double_click (*pGT_X, *pGT_Y);
			cout << "\tDouble clicked\r";
			break;
	default:
		cout << "ERROR at clicking function\n";
		break;
	}
firedraco (2623)   Link to this post
What is pclick_function? Is it an int*?
kempofighter (672)   Link to this post
Well then I guess the value passed to the switch wasn't a 1 or a 2. Any value other than 1 or 2 will cause the default to execute. Feel free to post a more complete example if you want any further analysis.
jcylam (104)   Link to this post
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
//Function variables
	bool flag = TRUE;
	int click_function;
	int *pclick_function = &click_function;

// Get screen resolution
	long Screen_Res_X = GetSystemMetrics ( SM_CXSCREEN );		//Screen size in x-axis
	long Screen_Res_Y = GetSystemMetrics ( SM_CYSCREEN );		//Screen size in y-axis

	cout << "Screen size x-axis: " << Screen_Res_X << endl;		//Prints x-axis size
	cout << "Screen size y-axis: " << Screen_Res_Y << endl;		//Prints y-axis size
	
	long GT_X = Screen_Res_X/2;		//Declare Gaze Tracker X coordinate
	long GT_Y = Screen_Res_Y/2;		//Declare Gaze Tracker Y coordinate

//Declare pointers
	long *pGT_X;
	long *pGT_Y;
	long *pScreen_Res_X;
	long *pScreen_Res_Y;

//Assign pointers
	pGT_X = &GT_X;
	pGT_Y = &GT_Y;
	pScreen_Res_X = &Screen_Res_X;
	pScreen_Res_Y = &Screen_Res_Y;

		cout << "Press \"ESC\" to end program\n";



	cout << "Press any key to continue\n";
	getchar();
	
	do
	{
		cout << "\nInsert value:\n1.Left click\n2.Double click\n";
		cin >> *pclick_function;

		get_XY (pGT_X, pGT_Y, pScreen_Res_X, pScreen_Res_Y, pclick_function);

jumps to the function
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
void get_XY (long *pGT_X, long *pGT_Y, long *pScreen_Res_X, long *pScreen_Res_Y, int *pclick_function)
{
//DECLARE VARIABLES for function
	bool flag = TRUE;
	bool click = FALSE;
	int click_counter = 0;

//DECLARATION OF VARIABLES for use in detecting automated click
	long lower_x, lower_y, upper_x, upper_y;

//DECLARE pointers
	long *plower_x = &lower_x;
	long *plower_y = &lower_y;
	long *pupper_x = &upper_x;
	long *pupper_y = &upper_y;

	//Setting lower and upper limit of cursor
	//For X axis
		if ( (*pGT_X -5) < 0 )
			lower_x = 0;
		else
			lower_x = (*pGT_X - 5);//end else if

		if ( (*pGT_X + 5) > *pScreen_Res_X )
			upper_x = *pScreen_Res_X;
		else
			upper_x = (*pGT_X + 5);//end else if

	//For Y axis
		if ( (*pGT_Y -5) < 0 )
			lower_y = 0;
		else
			lower_y = (*pGT_Y - 5);//end else if

		if ( (*pGT_Y + 5) > *pScreen_Res_Y )
			upper_y = *pScreen_Res_Y;
		else
			upper_y = (*pGT_Y + 5);//end else if
	//End setting limits

	printf ("\nStart: gt x %d, gt y %d, lower x %d, lower y %d, upper x %d, upper y %d\n", *pGT_X, *pGT_Y, *plower_x, *plower_y, *pupper_x, *pupper_y);

	int n = 2;	//sets the sampling rate before a click
	for (int j = 0; j < n; ++j)
	{
		loop_for_control (pGT_X, pGT_Y, n);

		if (check_position (pGT_X, pGT_Y, plower_x, plower_y, pupper_x, pupper_y))
		{
			++click_counter;
			if (click_counter == n)
			{
				click = TRUE;

			}
			cout << "counter: " << click_counter << endl;
		}
		else
		{
			cout << "not same" << endl;
		}

	}
cout << *pclick_function << "click_function\n";

	switch (*pclick_function)
	{
	case 1:
			Left_click_once (*pGT_X, *pGT_Y);
			cout << "\tLeft clicked\r";
			break;
	case 2:
			Double_click (*pGT_X, *pGT_Y);
			cout << "\tDouble clicked\r";
			break;
	default:
		cout << "ERROR at clicking function\n";
		break;
	}

	cout << "**********************************************\n";
}


when i enter 1 or 2 it prints out 1 clicked or 2 clicked but doesnt print left clicked or double clicked. when i enter sthg else the default works?????? does it hav to do with the pointer??
jsmith (3802)   Link to this post
Left_click_once and Double_click are being called. Your prints aren't displaying because
they don't flush stdout (cout) and there is no endl or \n to explicitly flush them.

Add a << std::endl or << '\n' to the end of lines 70 and 74.
jcylam (104)   Link to this post
fixed it.....somehow without altering the code, and doing like 10 times recompile it decides to work, donno what went wrong but its working now.

Thanks guys

This topic is archived - New replies not allowed.