【发布时间】:2019-10-14 02:26:53
【问题描述】:
下面是我的代码:
#include <iostream>
using namespace std;
int main()
{
int numboftimes, n, sumvalue = 0, strvalue = 0;
cout << "Enter Number of Times You Want The Loop to Run: ";
cin >> numboftimes;
for (n = 1; n <= numboftimes; n++)
{
sumvalue += n;
strvalue += 1;
}
cout << "You ran the for loop: " << numboftimes << " times. \n";
}
我无法在 for 循环中获得 cout 来打印出迭代。即 1+2+3+4+5 = 15。
【问题讨论】:
-
为什么不呢?当你尝试时会发生什么?请阅读How to Ask,然后阅读edit 您的问题并添加循环中打印的代码。