Dev C ++系列之和“不能用作函数”

时间:2013-10-03 17:08:39

标签: c++ function

/*
  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 ++课程并且遇到了一些困难我确信解决方案很简单,但我似乎无法解决它!

1 个答案:

答案 0 :(得分:4)

你遗漏了乘法运算符。将knwn =(n(n+1))/2;更改为knwn =(n * (n+1))/2;