/*
David Ballantyne
10/03/13
sum of a series
*/
#include <cstdlib>
#include <iostream>
using namespace std;
//no global constants
//no functioning prototypes
int main( int argc, const char* argv[] ){
//Declare Variables
short n,knwn,num,sum=0;
//prompt user
cout<<"input a number grater than 0";
cin>>n;
//Calculate
for( int num=1;num<=n;sum+=num++);
//known
knwn =(n(n+1))/2;
//output
cout<<"the sum of the series is"<<sum<<endl;
cout<<"the sum of the known series is"<<knwn<<endl;
system("PAUSE");
return EXIT_SUCCESS;
}
第30行知道它说“n”不能用作函数
我参加了一个c ++课程并且遇到了一些困难我确信解决方案很简单,但我似乎无法解决它!
答案 0 :(得分:4)
你遗漏了乘法运算符。将knwn =(n(n+1))/2;
更改为knwn =(n * (n+1))/2;
。