Hey guys, I just finished semester one at school, and I have been doing some coding exercises to keep sharp over the winter break, and I have been some new errors on this exercise. This exercise came from a "top-coder" practice problem that was used a few years ago.
Here is the problem statement:
Code:
........
A chessboard pattern is a pattern that satisfies the following conditions:
The pattern has a rectangular shape.
The pattern contains only the characters '.' (a dot) and 'X' (an uppercase letter X).
No two symbols that are horizontally or vertically adjacent are the same.
The symbol in the lower left corner of the pattern is '.' (a dot).
You are given two ints rows and columns. Write a method that computes the chessboard pattern with these dimensions, and returns it in a vector <string>. The elements of the return value correspond to rows of the pattern. Specifically, the first character of the last element of the return value represents the lower left corner
I addressed the problem by writing this function here:
Code:
vector <string> makeChessboard (int w, int h){
string row = "";
vector<string>Board();
int i = 0;
for(int height = 0; height < h; height++){
while(i<(w*h)){
for(int j = 0; j<w; j++){
if (i % 2 == 0){
row[j] = '.';
}
else{
row[j] = 'X';
}
i++;
}
}
Board[height] = row;
}
return Board;
}
I am getting many errors on line 23 were I say
Code:
Board[height] = row;
, including:
Code:
|23|warning: pointer to a function used in arithmetic
|23|error: assignment of read-only location '*(Board + ((unsigned int)height))'|
|23|error: cannot convert 'std::string' to 'std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >()' in assignment|
|25|error: conversion from 'std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > (*)()' to non-scalar type 'std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >' requested|
I have no clue why I am getting those errors, I have never ran into the first warning before, could someone please shed some light on what I am doing wrong? I tried using push back also to no avail. I don't know why it is complaining about trying to convert between types. If you guys could help out with this I would appreciate it a ton! Thanks a ton guys! I appreciate it!