LEe
LEe

Reputation: 1

I wrote a class. And when I specified the function, it failed

class equation 
{
    public :

    int k;
    int l;
    int t;
    float x1_value;
    float x2_value;
    float b1 = sqrt(l^2 -4*k*t);
    float equation1; 

    equation();
    ~equation();
    
};

float void equation::equation1() {

    if (b1 == 0)
    {
        float x1_value = -l/2*k;
        cout << " joongen. " <<x1_value <<endl;
    }

    else if (b1 > 0)
    {
        float x1_value = ((-l + sqrt(b1) / (2*k));
        float x2_value = ((-l - sqrt(b1) / (2*k));
        cout << "x is 2"<< x1_value < " x 2 is  "<< x2_value <<endl;
    }

    else 
    {
       cout <<"imagine number ."<<endl;
    }

    return (0);

};

The code produces this error:

error: two or more data types in declaration of 'equation1'
 float void equation::equation1() {
                                ^

Upvotes: 0

Views: 65

Answers (1)

skratchi.at
skratchi.at

Reputation: 1151

I can make out two problems.

First you define equation1 as a member variable with type float. You might want to change that into a function declaration.

// ...
float equation1();
// ...

The second problem is pointed out in the comments. If you implement your function, you should only use one return type. As I can only guess, what return type you would really want, I take float, since it is in your faulty function declaration.

// ...
float equation::equation1() {
    // ...
}
// ...

One extra thing, that disturbs me every time I see someone who is new with C++. Please, please, please, don't use using namespace std;. I assume you do so, because of the missing std::. You open up an fastly huge namespace. You may end up defining a function, with the same name and parameters and encounter a very cryptic error, which is nearly impossible to figure out.

Upvotes: 1

Related Questions