我目前正在学习通过使用网页程序编写C++,在那里我正在做一门课程。现在,最近我得到了下面的练习:C++在循环中添加数字练习
不断加在一起使用一段时间或do-while循环,使一个程序,要求用户输入数字,直到用户输入数字0
我写了下面的代码,希望它会带来的行使结论:
#include <iostream>
using namespace std;
int main(void){
int sum = 0;
int number;
do
{
cout <<endl;
cin >> number;
sum += number;
cout << "The total so far is: " << sum << endl;
} while (number != 0);
cout << "The total is: " << sum << endl;
}
然而,当我运行的代码我从网站的以下反馈(有两个环节一个在左边另一个在右边):
Instructions of the exercise and Webpage feedback on the exercise
你能告诉我什么我做错了,或者你能提出替代解决方案,然后我提供的代码?感谢您的任何反馈!
我想这不期待你用'cout << endl;'引入的额外换行符? – TartanLlama
你也应该打印'。'每个数字之后。 – Tempux
这工作正常在视觉工作室2013 –