C++ 带整数的While循环不起作用 #包括 使用名称空间std; int main(){ 整数=400; 整数计数=1; while(count==整数){ cout
C++ 带整数的While循环不起作用 #包括 使用名称空间std; int main(){ 整数=400; 整数计数=1; while(count==整数){ cout,c++,while-loop,integer,C++,While Loop,Integer,count==integer的计算结果为false。我想你的意思是while(count
count==integer
的计算结果为false。我想你的意思是while(count
你要求程序运行一个带有false条件的while循环,也就是说,你正在比较count
和integer
,前者的值为1
,后者设置为400
。
(count==integer)
将返回false,循环将被跳过
我想你想做的是
while(count
其中循环将以
count
设置为1开始,并以1为增量增加到400(根据count=count+1;
).您试过吗?您应该试一下!当while循环计算count
变量的条件值为1
时,integer
变量的条件值为400
。语句count==integer
也计算为false时,如果您有“int main”,则应从函数返回一个整数感谢您的快速回复!它帮助了很多。如果使用==计算为false,并且不能使用<作为布尔格式,我将如何为布尔格式变量执行循环?我只是对c++使用==
或!=
作为布尔格式非常陌生
#include <iostream>
using namespace std;
int main(){
int integer=400;
int count=1;
while (count == integer){
cout<< count<<endl;
count = count + 1;
}
}