简体   繁体   English

尝试使用 char 数组显示具有两位数的 3x3 表格

[英]Attempting to Display a 3x3 table with double digit numbers using char array

I am writing this program for class and I cannot seem to figure out how to make my Char array print values bigger than 1-9 as otherwise players will have to do math to be able to calculate which slot they want.我正在为 class 编写这个程序,我似乎无法弄清楚如何使我的 Char 数组打印值大于 1-9,否则玩家必须进行数学运算才能计算出他们想要的插槽。 Which I feel ruins the fun of the game.我觉得这破坏了游戏的乐趣。 However, I am newer to C++ and I cannot seem to get it to work.但是,我对 C++ 较新,我似乎无法让它工作。 Any help is appreciated, this is the Array, and this is the program.任何帮助表示赞赏,这是数组,这是程序。

class TTTBoard { public: class TTTBoard {公共:

void PrintBoard();
char board[9] = { '1','2','3','4','5','6','7','8','9' };
char board2[9] = { "10","11","12","13","14","15","16","17","18"};
char board3[9] =  { "19","20","21","22","23","24","25","26","27" };
int WinXY();
int WhosMove();
void Update();
int gameWin();
void AI();
void UserSelectASlot();
bool gameend();

}; };

My functions I have declared on in my source file, however whenever I try char * board2[9].......etc It gives me an error for many functions saying I cannot assign an int value to *char?我在源文件中声明了我的函数,但是每当我尝试 char * board2[9].......etc 它给我的许多函数一个错误,说我不能为 *char 分配一个 int 值?

This is one piece of code among many others from the UserSelectASlot();这是 UserSelectASlot() 中的许多其他代码中的一段; Function. Function。

else if (Spot == 10 && game.board2[0] != 'O' && game.board2[0] != 'X')
    {
        game.board2[0] = 'X';
    }

I also tried doing char string board[9][19] however that does not work either due to errors, over 100 so it stopped counting.我也尝试过 char string board[9][19] 但是由于错误,它也不起作用,超过 100 所以它停止计数。

My current errors for the first code above are "Too many Initializers" Any help is greatly appreciated!上面第一个代码的当前错误是“太多初始化程序”非常感谢任何帮助! Thanks!谢谢!

The 2nd and 3rd char arrays are actually arrays of strings (“) so change the declaration to:第 2 个和第 3 个字符 arrays 实际上是 arrays 字符串 (“) 所以将声明更改为:

const char* array[9] const char* 数组[9]

About the error you received, my guess is that you passed array[i] to a function that expects a char so replace it with array[i][0], array[i][1] those are the 2 characters in the string.关于您收到的错误,我的猜测是您将 array[i] 传递给了一个 function,它需要一个字符,所以用 array[i][0]、array[i][1] 替换它是字符串中的 2 个字符.

BTW, You don't need to work with characters but with numbers, integers and in the print function you can just map the int values to the right character.顺便说一句,您不需要使用字符,而是使用数字、整数,并且在打印 function 中,您只需 map 将 int 值转换为正确的字符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM