Hi,
I have homework assignment to make a minesweeper game using classes. In that game I have 3 lives,when I enter coordinates with I loose life,otherwise i get point. Here is how I tried to solve the problem,but I have some errors in it. Can you check it please and add something what I am missing.

#include<ctime>
#include<iostream>
#include<cstdlib>
using namespace std;
class grid
{           
      int table[8][8];
     for(int f=0;f<=7;f++)
     for(int g=0;g<=7;g++)
    table[f][g]=(rand()%2);     
     };
 int grid::selectCoords (int& x,int& y)
 {   
      cout<<"enter first coordinate:";
      cin>>x;
      cout<<"enter second coordinate:";
      cin>>y;
      }
     int grid::check(int& x,int& y,int& n,int table[8][8],int& p)
      {         
                  if(table[x][y]==1)
           {
                  n++;
                  cout<<"You lost one life!"<<3-n<<endl;                         
           }
           else if(table[x][y]==0)
           p++;
           cout<<"number of points:"<<p<<endl;
           if (x,y<=8)
       {
                  cout<<endl;
                  }
       else
       cout<<"invalid number"<<endl;
       }
           int main()
           {
               grid select;
               select.selectCoords(int& x,int& y);
               select.check(int x,int y);               
               do{                
                 select.selectCoords(int x,int y);
               select.check(int x,int y);
          }
          while(int n<3);
          cout<<"game over"<<endl;

               system("PAUSE");
               return 0;
               }

Recommended Answers

All 4 Replies

i see many syntax errors in your code. Few i will list. Rest you should compile your code.
In the check member function, you have so many parameters, but where you are calling the function,the number of parameters are different
Also the use of references is not proper.the way you are calling the functions is not at all correct. An easier way for you to do so is to have global variables where ever you feel to use refernces or have better understanding of references first.

class grid
{
int table[8][8];
for(int f=0;f<=7;f++)
for(int g=0;g<=7;g++)
table[f][g]=(rand()%2);
};

Ok, what is that? Class declaration, method or something else?

class grid
{
int table[8][8];
for(int f=0;f<=7;f++)
for(int g=0;g<=7;g++)
table[f][g]=(rand()%2);
};

Ok, what is that? Class declaration, method or something else?

I tried to declare class with that,but I have just learned classes and I am not very clear with them.

I tried to declare class with that,but I have just learned classes and I am not very clear with them.

I would really appreciate if anyone could help me solve this problem.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.