0
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() {
                                ^
Alan Birtles
  • 32,622
  • 4
  • 31
  • 60
LEe
  • 1
  • First of all please read [the help pages](http://stackoverflow.com/help), take the SO [tour], read [ask], as well as [this question checklist](https://codeblog.jonskeet.uk/2012/11/24/stack-overflow-question-checklist/). And learn how to [edit] your questions to improve them. – Some programmer dude Dec 06 '21 at 07:40
  • Secondly, have you tried to actually *read* the error message, the *complete* error message? What does it say? What do you think the "two or more data types" could mean? What is the declared return-type of the function? And if you still don't get it, read that faulty line out aloud to a room-mate or friend or even your pet. Do this a few times until you get it. :) – Some programmer dude Dec 06 '21 at 07:40
  • Another thing: in C++, `^` is a bitwise exclusive-OR operator (this is **not** a square of a number). Also, if both values are of type `int` then the result of division will also be an integer, not a floating point number (so, for example, `3 / 5` will result in `0`). – heap underrun Dec 06 '21 at 09:04
  • It looks like you need [a good book](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list). – molbdnilo Dec 06 '21 at 10:09

1 Answers1

1

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.

skratchi.at
  • 1,151
  • 7
  • 22