C++ 新手在这里。这段代码有什么问题或复杂吗?我的主要问题是我是否可以在 while (val <= v2) 中使用 v1 和 v2?
#include <iostream>
int main ()
{
std::cout << "Enter two numbers: " << std::endl;
int v1 = 0, v2 = 0;
std::cin >> v1 >> v2;
int sum = 0, val = v1;
while (val <= v2)
{
sum += val;
++ val;
}
std::cout << "The sum of " << v1 << " through " << v2 << " inclusive is " << sum << std::endl;
return 0;
}