C++ Buttons not working?

Hello, I'm new to this site, though I've looked to it for answers to many of my questions regarding C++ coding, though something is stumping me right now and I can't seem to find anything on it.

I'm designing a "Color memory game" for an assignment in my class, where the user is supposed to click on a box corresponding with the left-most box in the first set, which disappears after 1-3 seconds determined by the user.

One button works perfectly, I'm getting the correct/incorrect output that I'm looking for. However, the rest of the 4 buttons are not working, and I can't seem to figure out why.

This is the code that I currently have for the function (colors and colors2 are both arrays for the first and second set of displayed colors, no_colors is the number of colors inputted by the user to determine how many iterations the code will go through, and score is... well, the score. +2 for each correct, -2 for each incorrect):

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
void leftMouseClick(int* colors, int* colors2, int no_colors, int* score)
{
  int x = 0;
  int y = 0;
  bool correct = false;

  for (int j = 0; j < no_colors; j++)
  {
    gout << setPos(300, 400) << "Click on Color #" << (j+1) << endg;
    while(true)
    {
      if (leftMouse(x, y))
      {
	//check for colors

        //clicking box 1 at the bottom
	if ( (x > 50) && (x < 125) && (y > 300) && (y < 375) ){
	  if (colors2[0] == colors[j])
	  {
	    correct = true;
            gout << setPos(300,10) << "Correct!" << endg;
	  }
	  else if (colors2[0] != colors[j])
	  {
	     gout << setPos(300,10) << "INCORRECT ANSWER" << endg;
	     correct = false;
	  }

	  cout << correct << endl;

	  if (correct = true)
	    score = score + 2;
	  else if (correct = false)
	    score = score - 2;
	}

	//clicking box 2
	if ( (x > 150) && (x < 225) && (y > 300) && (y > 375) ){
	  if (colors2[1] == colors[j])
	  {
	     correct = true;
	     gout << setPos(300,10) << "Correct!" << endg;
	  }
	  else if (colors2[1] != colors[j])
	  {
	    gout << setPos(300,10) << "INCORRECT ANSWER" << endg;
            correct = false;
	  }
	cout << correct << endl;

	if (correct = true)
	  score = score + 2;
	else if (correct = false;
	  score = score - 2;
	}

	//clicking box 3
	if ( (x > 250) && (x < 325) && (y > 300) && (y > 375) ){
	  if (colors2[2] == colors[j])
	  {
	    correct = true;
	    gout << setPos(300,10) << "Correct!" << endg;
	  }
	  else if (colors2[2] != colors[j])
	  {
	    gout << setPos(300,10) << "INCORRECT ANSWER" << endg;
	    correct = false;
	  }
	cout << correct << endl;

	if (correct = true)
	  score = score + 2;
	else if (correct = false)
	  score = score - 2;

	}

	//clicking box 4
	if ( (x > 350) && (x < 425) && (y > 300) && (y > 375) )
        {
	  if (colors2[3] == colors[j])
	  {
	    correct = true;
	    gout << setPos(300,10) << "Correct!" << endg;
	  }
	  else if (colors2[3] != colors[j])
	  {
	    gout << setPos(300,10) << "INCORRECT ANSWER" << endg;
	    correct = false;
	  }			
	cout << correct << endl;

	if (correct = true)
	  score = score + 2;
	else if (correct = false)
	  score = score - 2;
	}

		//clicking box 5
	if ( (x > 450) && (x < 525) && (y > 300) && (y > 375) ){

	  if (colors2[4] == colors[j])
	  {
	    correct = true;
	    gout << setPos(300,10) << "Correct!" << endg;
	  }
	  else if (colors2[4] != colors[j])
	  {
	    gout << setPos(300,10) << "INCORRECT ANSWER" << endg;
	    correct = false;
	  }
	cout << correct << endl;

	if (correct = true)
	  *score = *score + 2;
	else if (correct = false)
          *score = *score - 2;
        }
      }
    }
  }
}
Last edited on
Nevermind, I found the issue; I marked the second y as >375, rather than <375. Curse my bad eyesight...
Topic archived. No new replies allowed.