Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 对于循环C++;Don';不要停下来等我 shipname[0]=“飞机”; 船名[1]=“战列舰”; shipname[2]=“Destroyer”; 船名[3]=“潜艇”; 船名[4]=“巡逻艇”; cout>Isplaceship; 如果((Isplaceship=“Y”)|(Isplaceship=“Y”)) { 对于(int i=0;i>dir; 我自己做了一些编码: shipname[0] = "Aircraft"; shipname[1] = "Battleship"; shipname[2] = "Destoryer"; shipname[3] = "Submarine"; shipname[4] = "Patrol Boat"; cout << "Do you wish to place your own ships. Y/N "; cin >> Isplaceship; if ((Isplaceship = "Y") | (Isplaceship = "y")) { for (int i = 0; i < 5; i++){ cout << "Please Enter a location for your " << shipname[i] << endl; cout << "type row. col & direction(0 horizontal, 1 vertical) split by spaces: "; cin >> x >> y >> dir; cout << "your input is " << x << " " << y << " " << dir; } cout << endl; } else if ((Isplaceship = "N") | (Isplaceship = "n")) { }; }_C++_Loops - Fatal编程技术网

C++ 对于循环C++;Don';不要停下来等我 shipname[0]=“飞机”; 船名[1]=“战列舰”; shipname[2]=“Destroyer”; 船名[3]=“潜艇”; 船名[4]=“巡逻艇”; cout>Isplaceship; 如果((Isplaceship=“Y”)|(Isplaceship=“Y”)) { 对于(int i=0;i>dir; 我自己做了一些编码: shipname[0] = "Aircraft"; shipname[1] = "Battleship"; shipname[2] = "Destoryer"; shipname[3] = "Submarine"; shipname[4] = "Patrol Boat"; cout << "Do you wish to place your own ships. Y/N "; cin >> Isplaceship; if ((Isplaceship = "Y") | (Isplaceship = "y")) { for (int i = 0; i < 5; i++){ cout << "Please Enter a location for your " << shipname[i] << endl; cout << "type row. col & direction(0 horizontal, 1 vertical) split by spaces: "; cin >> x >> y >> dir; cout << "your input is " << x << " " << y << " " << dir; } cout << endl; } else if ((Isplaceship = "N") | (Isplaceship = "n")) { }; }

C++ 对于循环C++;Don';不要停下来等我 shipname[0]=“飞机”; 船名[1]=“战列舰”; shipname[2]=“Destroyer”; 船名[3]=“潜艇”; 船名[4]=“巡逻艇”; cout>Isplaceship; 如果((Isplaceship=“Y”)|(Isplaceship=“Y”)) { 对于(int i=0;i>dir; 我自己做了一些编码: shipname[0] = "Aircraft"; shipname[1] = "Battleship"; shipname[2] = "Destoryer"; shipname[3] = "Submarine"; shipname[4] = "Patrol Boat"; cout << "Do you wish to place your own ships. Y/N "; cin >> Isplaceship; if ((Isplaceship = "Y") | (Isplaceship = "y")) { for (int i = 0; i < 5; i++){ cout << "Please Enter a location for your " << shipname[i] << endl; cout << "type row. col & direction(0 horizontal, 1 vertical) split by spaces: "; cin >> x >> y >> dir; cout << "your input is " << x << " " << y << " " << dir; } cout << endl; } else if ((Isplaceship = "N") | (Isplaceship = "n")) { }; },c++,loops,C++,Loops,我不太确定你为什么会得到这样的结果,但我认为你可以将我的代码与你的代码进行比较,或者做一些其他类似的编码,这可能会帮助你找出你遗漏的一些细节。将此更改为:if((Isplaceship=“Y”)(Isplaceship=“Y”)改为:if((Isplaceship==“Y”)(Isplaceship==“Y”))你能再显示一点代码吗?你确定这一行cin>>x>>y>>dir;在for循环内吗?是的,它在循环内,很抱歉我没有在这里正确显示代码。你确定cin此时没有处于失败状态吗?可能包括你的全部代

我不太确定你为什么会得到这样的结果,但我认为你可以将我的代码与你的代码进行比较,或者做一些其他类似的编码,这可能会帮助你找出你遗漏的一些细节。

将此更改为:
if((Isplaceship=“Y”)(Isplaceship=“Y”)
改为:
if((Isplaceship==“Y”)(Isplaceship==“Y”))

你能再显示一点代码吗?你确定这一行
cin>>x>>y>>dir;
在for循环内吗?是的,它在循环内,很抱歉我没有在这里正确显示代码。你确定
cin
此时没有处于失败状态吗?可能包括你的全部代码。你发布的内容应该可以正常工作。啊之后,你说我去检查我的Isplaceship类型,它以前是bool…我现在改为String,现在它工作了,谢谢你们的帮助。
int i = 0;
for (int i = 0; i <= 5; ++i)
{
    cout << "input a number:" << endl;
    cin >> i;
    cout << "The number you input is:" << i << endl;
}
input a number:
1
The number you input is:1
input a number:
2
The number you input is:2
input a number:
3
The number you input is:3
input a number:
4
The number you input is:4
input a number:
5
The number you input is:5