这段C++输出符号的代码总是出错?
这段代码总是编译不通过,我刚开始用C++,对初始化还不熟,谁能帮我改一下,并解释一下,谢谢谢谢!!#include"stdafx.h"#include<iostream>...
这段代码总是编译不通过,我刚开始用C++,对初始化还不熟,谁能帮我改一下,并解释一下,谢谢谢谢!!
#include "stdafx.h"
#include <iostream>
void PrintBoard()
{
char Board[9][11];
int i, j;
for( i = 0; i < 9; i++ )
for( j = 0; j < 11; j++ ){
if( i == 0 || i == 8 && j == 0 || j== 10 )
strcpy(Board[i][j]," + ");
else if( i == 4 && j == 1 || i == 4 && j == 9 )
strcpy(Board[i][j]," @ ");
else if( 3 < i < 4 && 5 < j < 6 || 6 < i < 7 && 5 < j < 7 )
strcpy(Board[i][j]," * ");
else if( i == 3 && j ==1 || i == 3 && j == 9 || i == 4 && j == 2 || i == 4 && j == 8 || i == 5 && j == 1 || i == 5 && j == 9 )
strcpy(Board[i][j]," # ");
}
for( i = 0; i < 9; i++ )
for( j = 0; j < 11; j++ )
std::cout << Board[i][j];
}
int _tmain(int argc, _TCHAR* argv[])
{
PrintBoard();
return 0;
}
改了一下,编译通过了,但是输出结果不对,我想输出的是
+++++++++++
+ +
+ *** +
+# *** #+
+@# #@+
+# *** #+
+ *** +
+ +
+++++++++++ 展开
#include "stdafx.h"
#include <iostream>
void PrintBoard()
{
char Board[9][11];
int i, j;
for( i = 0; i < 9; i++ )
for( j = 0; j < 11; j++ ){
if( i == 0 || i == 8 && j == 0 || j== 10 )
strcpy(Board[i][j]," + ");
else if( i == 4 && j == 1 || i == 4 && j == 9 )
strcpy(Board[i][j]," @ ");
else if( 3 < i < 4 && 5 < j < 6 || 6 < i < 7 && 5 < j < 7 )
strcpy(Board[i][j]," * ");
else if( i == 3 && j ==1 || i == 3 && j == 9 || i == 4 && j == 2 || i == 4 && j == 8 || i == 5 && j == 1 || i == 5 && j == 9 )
strcpy(Board[i][j]," # ");
}
for( i = 0; i < 9; i++ )
for( j = 0; j < 11; j++ )
std::cout << Board[i][j];
}
int _tmain(int argc, _TCHAR* argv[])
{
PrintBoard();
return 0;
}
改了一下,编译通过了,但是输出结果不对,我想输出的是
+++++++++++
+ +
+ *** +
+# *** #+
+@# #@+
+# *** #+
+ *** +
+ +
+++++++++++ 展开
3个回答
展开全部
1、strcpy(Board[i][j]," + "); // strcpy(&Board[i][j]," + ");
2、3 < i < 4 //这个是习惯上的用法,呵呵,应该是(3 < i && i < 4)
另外不知道你的本意是什么?是这样的
if( i == 0 || i == 8 && j == 0 || j== 10 ) ?
还是if( (i == 0 || i == 8) && (j == 0 || j== 10) ) 呢?
类似的if中的条件你最好都看下,否则谁都不知道程序最终输出的什么...
2、3 < i < 4 //这个是习惯上的用法,呵呵,应该是(3 < i && i < 4)
另外不知道你的本意是什么?是这样的
if( i == 0 || i == 8 && j == 0 || j== 10 ) ?
还是if( (i == 0 || i == 8) && (j == 0 || j== 10) ) 呢?
类似的if中的条件你最好都看下,否则谁都不知道程序最终输出的什么...
展开全部
#include <cstring>
#include <iostream>
void PrintBoard()
{
char Board[9][11];
int i, j;
for( i = 0; i < 9; i++ )
for( j = 0; j < 11; j++ ){
if( i == 0 || i == 8 && j == 0 || j== 10 )
Board[i][j] = '+';
else if( i == 4 && j == 1 || i == 4 && j == 9 )
Board[i][j] = '@';
else if( 3 < i < 4 && 5 < j < 6 || 6 < i < 7 && 5 < j < 7 )
Board[i][j] = '*';
else if( i == 3 && j ==1 || i == 3 && j == 9 || i == 4 && j == 2 || i == 4 && j == 8 || i == 5 && j == 1 || i == 5 && j == 9 )
Board[i][j] = '#';
}
for( i = 0; i < 9; i++ )
for( j = 0; j < 11; j++ )
std::cout << Board[i][j];
}
int main()
{
PrintBoard();
return 0;
}
------------------------------------------------------
去翻书,查一下 strcpy() 是怎么用的。
#include <iostream>
void PrintBoard()
{
char Board[9][11];
int i, j;
for( i = 0; i < 9; i++ )
for( j = 0; j < 11; j++ ){
if( i == 0 || i == 8 && j == 0 || j== 10 )
Board[i][j] = '+';
else if( i == 4 && j == 1 || i == 4 && j == 9 )
Board[i][j] = '@';
else if( 3 < i < 4 && 5 < j < 6 || 6 < i < 7 && 5 < j < 7 )
Board[i][j] = '*';
else if( i == 3 && j ==1 || i == 3 && j == 9 || i == 4 && j == 2 || i == 4 && j == 8 || i == 5 && j == 1 || i == 5 && j == 9 )
Board[i][j] = '#';
}
for( i = 0; i < 9; i++ )
for( j = 0; j < 11; j++ )
std::cout << Board[i][j];
}
int main()
{
PrintBoard();
return 0;
}
------------------------------------------------------
去翻书,查一下 strcpy() 是怎么用的。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
指教
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询