int main() { std::cout << "please enter two numbers"; int v1, v2; std::cin >> v1 >> v2; //std::cout << std::endl; int lower, higher; if (v1 <= v2) { lower = v1; higher = v2; } else { lower = v2; higher = v1; } int sum=0; for (int sal = lower; sal<= higher; ++sal) { sum += sal; } std::cout << "the sum of" << v1 << "and" << v2 << "is" << sum; return 0; }
Exercise 1.14:
What happens in the program presented in this section if the input values are equal?
如果输入值相等,本节展示的程序将产生什么问题?
输出的还是原来的数。
Exercise 1.15:
Compile and run the program from this section with two equal values as input. Compare the output to what you predicted in the previous exercise. Explain any discrepancy between what happened and what you predicted.