虽然循环与整数不起作用


#include <iostream>
using namespace std;
int main(){
int integer=400;
int count=1;
while (count == integer){
cout<< count<<endl;
count = count + 1;
}
}

这基本上是我在项目中使用的。似乎没有输出。帮助?

count == integer正在评估 false。我想你的意思是while (count < integer).

你要求程序运行一个while循环,有一个假条件,即你正在比较countinteger,其中前者的值是1,后者设置为400(count == integer)将返回 false,并且循环将被跳过。

我认为你想做的是 while (count < integer)其中循环将从count设置为 1 开始,并以 1 为增量增加到 400(根据 count = count + 1; (。

最新更新