I have to write a memory game, where the user gives a file name and that file reads in 8 strings that will be placed on the board. The code I have so far is down below, if anyone can help me fix it up I would appreciate it.
#include <iostream>
#include <fstream>
#include <ctime>
#include <string>
#include <iomanip>
using namespace std;
const int size = 4; //controls dimensions of array, here there will be a 4 X 4 grid
void displaygrid(int ch1, int ch2, string board[][size], bool dec[]);
void getgrid(string filename, string output[][size], bool choice []);
void drawbar();
int getchoice(int num1);
int main()
{
srand((int)time(NULL));
int ch1 = 1, ch2 = 1;
string board [size][size];
bool dec [size];
string filename;
cout << " How good is your memory? " << endl << endl << endl << " Enter the name of the file ";
getline(cin,filename);
getgrid(filename,board,dec);
drawbar();
displaygrid(ch1,ch2,board,dec);
drawbar();
return 0;
}
void drawbar()
{
cout << "--------------------------------------------------------" << endl;
}
int getchoice(int num1) //Takes choice for match during each round, so it can be checked
{
cout << "Enter your choice (1-16) ";
cin >> num1;
return num1;
}
void getgrid(string filename, string output[][size], bool choice []) //gets the name of the file and put it in to the array
{
ifstream inf;
inf.open(filename.c_str());
string name; // read in stuffs from the file.
inf >> name;
int ct = 0;
int random = rand() % 8;
while (inf) // to read in the names from the file to array.
{
string names[8];
names[ct]= name;
inf >> names[ct];
ct++;
}
for(int row = 0; row < size; row++)
{
for(int col = 0; col < size; col++)
{
string names[8];
names[ct]= name;
output [row][col] = names[random];
cout << output[row][col];
}
}inf.close();
}
void displaygrid(int ch1, int ch2, string board[][size], bool dec[])
{
int ctr = 0;
for (int r = 0; r < size; r++)
{
for (int c = 0; c < size; c++)
{
if (dec[size] == true || ch1 == r * size + c + 1 || ch2 == r * size + c + 1)
cout << setw(15) << board[r][c];
else
cout << setw(15) << "***" << ctr << "***" << board[r][c];
ctr++;
}
}
cout << endl;
}
void begingrid (bool dec[16])
{
for (int ct = 0; ct < 16; ct++)
{
dec[ct]= false;
ct++;
}
}