Hi Im trying to create a random 2D array (3 x 3) so that numbers 1-9 will randomly be placed in the grid behind the '?' shown in coveredarray but in the guessarray just wanted to know if im doing right, im faily new to C++, also i wanted how do i go about changing the Playarray so that user can be asked to enter a row and column number to type in a number between 1-9 and see if it matches the number placed there by the random array i also want to allow the game to remember it and saying it's only got a limited of number turns left, i dont know if i've done it right!? If you got spare time to look at my code i will very much appreshiate it!
Thanks
`Inline Code Example Here`
#include<iostream>
#include<conio.h>
#include<string>
#include<cstdlib>
#include<ctime>
using namespace std;
int pause() //Funtion for pause
{
int in;
scanf("%c",&ch);
getint();
return 0;
}
int main ()
{
cout<< "Welcome to Guess Game" <<endl; //I'm inserting a message so that when the game loads the user will be welcomed into the game.
//This is the Character Array
char coveredarray [3][3] = {{'?','?','?'},
{'?','?','?'},
{'?','?','?'}};
for(int row = 0; row < 3; row++)
{
for(int column = 0; column < 3; column++)
{
cout << coveredarray[row][column] << " ";
}
cout << endl;
}
//This is the Guess Array
int myarray[3][3]={{'0','0','0'},
{'0','0','0'},
{'0','0','0'}}
srand (unsigned time())
int numbersentered=0;
for (int i=1; i<=9; i++)
{
while (i>numbersentered)
{
int x=rand()%3;
int y=rand()%3;
if (myarray[x][y]==0)
{
myarray[x][y]=i;
numbersentered++;
}
}
}
int playarray[3][3];{{'?','?','?'},
{'?','?','?'},
{'?','?','?'}}; //im creating a memory array
int row, column;
int turn= 1, mine_ctr=0;
int play_row, play_column;
while (turn < 9) { //I'm going to use While Loops
cout<< " "<< playarray <<endl;
cout<<endl;
if((play_row > 1) && (play_column < 3))
{
cout<< "Please enter a number of row and column" <<endl; //This is a message telling the user to enter a number between 1 and 9
system ("pause") ;
continue;
if((guessarray[play_row-1][play_column-1] <= 9)
cout << "Number found" << endl; //I'm creating a message which will tell them that they've found a mine.
displayarray[play_row-1][play_colum-1] ='' ;
mine_ctr++;//This will keep a track of Mines located
for (int row=0; row<3; row++)
{
cout<<coveredarray [row][column]<<" ";
}
cout<<endl;
}
}
else
{
cout << "Wrong Number" << endl; //This is going to input a message when no mines are found.
displayarray[play_row-1][play_column-1] = '?';
cout << endl;
}
if(guessarray[play_row-1][play_column-1] == 1;
{
cout << "Please choose another position" //I'm creating a message so that if the user doesnt put a number 1-5 they will be reminded to do so.
system("pause");
continue;
guessarray[play_row-1][play_row-1]=1;
if(guess_ctr =9)
{
cout << "You have found all the numbers" << endl; //This message will appear if the user has found all 10 mines.
break;
}
turn++;
}
if (turn==10)
{
cout << "Unfortunatly you have lost" << endl; //This is a message telling them that have basically lost.
_getch()
}
`Inline Code Example Here`