help with this question

Write your question here.
Question:You are given a grid as shown in the figure below. You can determine the color and
number of each square from the grid. Write a C++ program that inputs two numbers within the
grid range (if not in range, you can ask the user to enter again). Your program will determine if
the two squares entered in this grid have the same color or not and display the appropriate
message. Your goal is to reveal all the squares(match all the squares), that means you will keep
on asking the user to enter two numbers from the range unless all the squares are correctly
identified. Once a square is correctly identified, make sure that the user does not repeat the
numbers of the revealed squares. If he does, give him a warning and ask to enter values again
You can give max of 3 warnings, on the forth warning you will end the program, even if the grid
is not completely revealed. On each iteration you will make sure that the numbers entered do
not match with any of the correctly guessed squares.
Note: You cannot use arrays to store the matrix information.

I have done half of it but i don't know how to reveal all squares and then make sure user doesn't enter it again ....Please save me from this evil assignment.

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
#include<iostream>
using namespace std;
int main ()
{
    // BY Taimur Hussain Khan ASSIGNMENT 2 (SE-S)
    int a,b,i=0;   // Declaring variables
    
    
 
    do
    {
    cout<<"Enter Your Two Numbers:\n";
    cin>>a>>b;        //First Number
    
    if (a<=0 || a>36 || b<=0 || b>36)  // Checking if numbers entered are in range
    {
    cout<<"Enter a number between 1 and 36\n";
    }
    else if ((a==1 || a==6 || a==7 || a==12 || a==17 || a==20 || a==28 || a==33) && (b==1 || b==6 || b==7 || b==12 || b==17 || b==20 || b==28 || b==33 ))   //For Green
    {
    cout<<"The Number Entered Are In Same Grid and have SAME colour!\n";
    }
      else if 
      ((a==2 || a==11 || a==13 || a==18 || a==19 || a==24 || a==29 || a==32) && (b==2 || b==11 || b==13 || b==18 || b==19 || b==24 || b==29 || b==32 ))   //For Red
      {
      cout<<"The Number Entered Are In Same Grid and have SAME colour!\n";
      }
      else if 
      ((a==3 || a==10 || a==14 || a==23 || a==25 || a==30 || a==31 || a==36) && (b==3 || b==10 || b==14 || b==23 || b==25 || b==30 || b==31 || b==36 ))   //For Cyan
      {
      cout<<"The Number Entered Are In Same Grid and have SAME colour!\n";
      }
      else if 
      ((a==4 || a==9 || a==15 || a==22 || a==26 || a==35) && (b==4 || b==9 || b==15 || b==22 || b==26 || b==35))  //For Orange
      {
      cout<<"The Number Entered Are In Same Grid and have SAME colour!\n";
      }
      else if 
      ((a==5 || a==8 || a==16 || a==21 || a==27 || a==34) && (b==5 || b==8 || b==16 || b==21 || b==27 || b==34)) //For Grey
      {
      cout<<"The Number Entered Are In Same Grid and have SAME colour!\n";
      }
      
         
    else cout<<"The Number Entered Are NOT In Same Grid and NOT SAME colour\n"; 
    i++; 
      }while(i<20);
    
      
    
    
 }   
Last edited on
Are we learning formatting and naming yet?
https://www.cplusplus.com/forum/general/274215/
i m trying .... :(
Well you can start by renaming 'a' to 'row' and 'b' to 'col'.
Your assignment talks about a grid, where is your grid variable?

You have a concept of whether a square is revealed or not, where is that?

> You are given a grid as shown in the figure below.
Yeah, that's not really working for us.

Some thoughts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
enum colours {
  green,
  red,
  cyan,
  orange,
  grey
};
colours grid[6][6] = {
  { grey, grey, grey, grey, grey, grey },
  { grey, grey, grey, grey, grey, grey },
  { grey, grey, grey, grey, grey, grey },
  { grey, grey, grey, grey, grey, grey },
  { grey, grey, grey, grey, grey, grey },
  { grey, grey, grey, grey, grey, grey },
};
bool revealed[6][6] = {
  { false }
};


So now you ask the user to enter two positions
cin >> r1 >> c1 >> r2 >> c2;


An error check, you already used that square
if ( revealed[r1][c1] || revealed[r2][c2] )


A correct guess
1
2
3
4
if ( grid[r1][c1] == grid[r2][c2] ) {
  revealed[r1][c1] = true;
  revealed[r2][c2] = true;
}

From the OP's first post:

Note: You cannot use arrays to store the matrix information.

No arrays/matrices?
No problem, use a single string and a 1D<->2D converter function.

> Note: You cannot use arrays to store the matrix information.
Instructors who do this seem more interested in teaching magic tricks than actual programming.

NO manager in a professional s/w development environment ever tells you "implement x, but don't use y to do it".

Topic archived. No new replies allowed.