c++超简单问题

来源:百度知道 编辑:UC知道 时间:2024/07/07 21:31:32
#include<iostream.h>
#include<iomanip.h>
int main(){
int i,j;
char shu;
for(i=1;i<=7;i++){
for(j=1;j<=7;j++){
if(j=1||j=7) shu='A';
else if(j=2||j=6) shu='B';
else if(j=3||j=5) shu='C';
else shu='D';
if(i+j<=4||i+j>=12||j-i>=4||i-j<=4) cout<<" ";
else cout<<n;
}
cout<<endl;
}
return 0;
}

提示错误 error C2106: '=' : left operand must be l-value。。

if(j=1||j=7) shu='A';
else if(j=2||j=6) shu='B';
else if(j=3||j=5) shu='C';
这里括号中的所有 = 都改成 ==
此外还有其他的错误。修改后的代码如下:
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
int i, j;
char shu;

for (i = 1; i <= 7; i++)
{
for (j = 1; j <= 7; j++)
{
if (j == 1 || j == 7)
shu = 'A';
else if (j == 2 || j == 6)
shu = 'B';
else if (j == 3 || j == 5)
shu = 'C';
else
shu = 'D';

if (i + j <= 4 || i + j >= 12 || j - i >= 4 || i - j <= 4)
cout << " ";
else
cout << endl;
}

cout << endl;
}

return 0;
}

==是赋值吧?=好像是定义
很久没接触C++了 我还没过 O(∩_∩)O哈哈~

if(j=1||j=7)
类似这里的=都改成==

比较大小应该用==而不是=

else cout<