1 Attachment(s)
Jumping into c++ chapter 14 problem 5 (Collect 4)
Hi guys I m trying to do a couple of functions which enable to get a board of a certain width and length. Once the user choose how much broad the board will be, I want to make appear on each empty slot this "-", by using system ("cls") (because is the only way I ve learnt so far).
This is the code I ve written:
Code:
#include <iostream>
#include <cstdlib>
using namespace std;
void DisplayBoard (char **p_p_board, int length, int width);
void Board (char **p_p_board, int length, int width)
{
p_p_board = new char* [length];
for (int i=0; i<length; i++)
{
p_p_board [i] = new char [width];
}
DisplayBoard (p_p_board, length, width);
}
void DisplayBoard (char **p_p_board, int length, int width)
{
cout<<"COLLECT FOUR"<<endl;
system("cls");
for (int x=1; x<length+1; x++)
{
cout<<x<<" ";
}
cout<<endl;
for (int i =0; i<length; i++)
{
cout<<endl;
for(int j=0; j<width; j++)
{
cout<< p_p_board [i][j] = "-"<< " "; // error
}
}
}
I know it doesn't give anything yet, cause I haven t put main, but when I try to build it it tells me:
"|30|error: invalid operands of types 'const char [2]' and 'const char [2]' to binary 'operator<<'"
This is referred to the line of code where I added the comment "//error"
Could anyone tell me what to change?
(P.S. this chapter is supposed to treat multidimentional arrays and pointers to pointers)