Hello,
I have an assignment to convert some given jave code into c++. I am currently having an issue wherein when I run the program it tells me that: error C2660: 'approximateSqrt' : function does not take 1 arguments. Any suggestions for moving forward would be appreciated. I have the following:

#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>

using namespace std;

// Function Prototyping
double getValue();
double getInitialGuess();
double approximateSqrt();



int main()
{
    double x = getValue();
    double xSqrt = approximateSqrt(x);
    cout<<"\nsqrt( %1.6f ) = %1.6f\n", x, xSqrt ;
}

// FUNCTION 1
double getValue()
{
    double value;
    cout<<"Enter value (>0) whose square root will be computed: ";
    cin>>value;
    while ( value <= 0 )
    {

        cout<<"Invalid value "<<value<<" <= 0" ;
        cout<<endl<<" -- try again";
        cout<<endl<<"Enter value (>0): ";
        cin>>value;
    }
    return value;
}

// FUNCTION 2
double getInitialGuess( double value )
{
    return value / 2.0;
}

// FUNCTION 3
double approximateSqrt( double value )
{
    double epsilon = 0.00001;
    double x = getInitialGuess( value );

    //System.out.printf( "sqrt( %1.6f ) = %1.6f\n", value, x );
    cout<<"sqrt( %1.6f ) = %1.6f\n", value, x;
    // SOMETHING TO DO WITH CMATH
    while ( abs( value - x * x ) > epsilon )
    {
        double tx = x;
        x = 0.5 * ( x + ( value / x ) );
        //System.out.printf( "sqrt( %1.6f ) = 0.5 * ( %1.6f + ( %1.6f / %1.6f ) ) = %1.6f\n", value, tx, value, tx, x );
        cout<<"sqrt( %1.6f ) = 0.5 * ( %1.6f + ( %1.6f / %1.6f ) ) = %1.6f\n", value, tx, value, tx, x;
    }
    return x;
}

On line 11 your function prototype says that approximateSqrt() takes no parameters so that is where that error is coming from. To fix it change that line to double approximateSqrt(double);

Thanks for helping me even on Easter. I finished my code and that was what I needed to fix. Thanks again!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.