错误:参数太少,无法运行

时间:2021-06-22 22:48:13

I know that there is a lot of similar questions, but I'm too new. so my problem is that I have to do a makefile and compile my project, but at some point it returns error.

我知道有很多类似的问题,但我太新了。所以我的问题是我必须做一个makefile并编译我的项目,但是在某些时候它会返回错误。

Main.cpp

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

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

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;
}

also I have InitialGuess.h

我也有InitialGuess.h

int InitialGuess(int number, float y);

and sqrtcalc.h

和sqrtcalc.h

int SquareRoot(int number, int th);

and a makefile

和一个makefile

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

It returns an error

它返回一个错误

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

SqrtCalc 7 error at this point

在这一点上出现了SqrtCalc 7错误。

2 个解决方案

#1


1  

error is self explanatory:

错误是自我解释:

in .h file you defined int InitialGuess(int number, float y); - with 2 arguments, but in .cpp file int InitialGuess(int number) - with one

在.h文件中定义了int InitialGuess(int number, float y);-有两个参数,但是在。cpp文件中有一个参数

the same problem with SquareRoot function

方形函数也有同样的问题

#2


2  

This is the declaration of your function:

这是你的职能声明:

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

and this is how you called it:

这就是你所谓的:

SquareRoot(number, th);

You're missing the third argument.

你漏掉了第三个论点。

Moreover, InitialGuess takes two arguments but you have it one.

此外,InitialGuess有两个参数,但只有一个参数。

#1


1  

error is self explanatory:

错误是自我解释:

in .h file you defined int InitialGuess(int number, float y); - with 2 arguments, but in .cpp file int InitialGuess(int number) - with one

在.h文件中定义了int InitialGuess(int number, float y);-有两个参数,但是在。cpp文件中有一个参数

the same problem with SquareRoot function

方形函数也有同样的问题

#2


2  

This is the declaration of your function:

这是你的职能声明:

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

and this is how you called it:

这就是你所谓的:

SquareRoot(number, th);

You're missing the third argument.

你漏掉了第三个论点。

Moreover, InitialGuess takes two arguments but you have it one.

此外,InitialGuess有两个参数,但只有一个参数。