2013-10-14 100 views
-3

我知道有很多類似的問題,但我太新了。所以我的問題是我必須做一個makefile並編譯我的項目,但在某些時候它會返回錯誤。錯誤:功能參數太少

Main.cpp的

#include <iostream> 
#include <stdlib.h> 
#include "SquareRootCalculation.h" 
using namespace std; 
int main(int argc, char* argv[]) 
{ 
    int number = atoi(argv[0]); 
    int th = atoi(argv[1]); 
    float result = SquareRoot(number, th); 
return 0; 
} 

InitialGuess.cpp

#include <iostream> 
#include <math.h> 
using namespace std; 
int InitialGuess(int number) 
{ 
    float numberLength = 0; 
for(; number != 0; number /= 10, numberLength++); 
float n = nearbyint(sqrt(numberLength)); 
float y = numberLength * pow(10, n); 
return 0; 
} 

SqrtCalc.cpp

#include <iostream> 
#include "InitialGuess.h" 
#include <math.h> 
using namespace std; 
int SquareRoot(int number, int th, float y) 
{ 
int initialGuess = InitialGuess(y); 
float x = initialGuess; 
for (int k=1; k< th; ++k) 
    { 
     x = (x + (number/x))/2; 
    } 
cout<<x;  
return 0; 
} 

還我InitialGuess.h

int InitialGuess(int number, float y); 

和sqrtcalc.h

int SquareRoot(int number, int th); 

和一個生成文件

all: 
g++ Main.cpp InitialGuess.cpp SquareRootCalculation.cpp -o FR  

它在這一點上返回一個錯誤

InitialGuess.h 1 In function 'int SquareRoot (int,int,float)' 
InitialGuess.h "too few arguments 'int InitialGuess(int, float)' 

SqrtCalc 7錯誤

回答

1

誤差是自我解釋:

在你定義int InitialGuess(int number, float y); .h文件中 - 以2個參數,但在.cpp文件int InitialGuess(int number) - 一個

同樣的問題SquareRoot功能

2

這是你的函數的聲明:

int SquareRoot(int number, int th, float y) 

,這是你怎麼把它稱爲:

SquareRoot(number, th); 

你錯過ŧ他第三個論點。

此外,InitialGuess需要兩個參數,但你有它。