我写了这段代码:
int sum,number;
sum=0;
number=1;
while(number<=11)
{
sum=sum+number;
cout << sum;
number++;
}
cout << "The sum of the fist 11 is" cout << sum;
它正在编译并给出错误:
17 37 C:\cprograms\main.cpp [Error] expected ';' before 'cout'
我无法理解我做错了什么?
我在while循环结束后放置了;
,但它仍然不起作用。
答案 0 :(得分:3)
用
替换你的最后一行cout << "The sum of the fist 11 is" << sum;
答案 1 :(得分:1)
更改以下行:
cout << "The sum of the fist 11 is" cout << sum;
到
cout << "The sum of the fist 11 is";
cout << sum;
答案 2 :(得分:0)
在这里。作品,
#include<iostream>
using namespace std;
int main(void)
{
int sum, number;
sum=0;
number=1;
while(number<=11)
{
sum = sum + number;
cout<<sum<<endl;
number++;
}
cout << "The sum of the fist 11 is "<<sum;
}
在声明中,您不能多次写cout
,只需<<