2013-10-03 55 views
0
/* 
    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」不能用作函數一個系列的開發++總和「不能被用作函數」

我在介紹Ç很++類和具有小小的困難我相信解決方案很簡單,但我似乎無法找到它!

回答

4

您遺漏了乘法運算符。將knwn =(n(n+1))/2;更改爲knwn =(n * (n+1))/2;

相關問題