0

error shows up on the third line if(ungefarlika(a,b)){

double a = 0.3;
double b = 0.1 + 0.1 + 0.1;
if ( ungefarlika(a,b) ){           
    cout << "a och b har ungefär samma värden" << endl;
    if (a==b)
        cout << "De har samma värden" << endl;
    else {
        cout << "Men bara ungefär" << endl;
    }
    else cout << "a och b är inte särskilt lika" << endl;
  }
  • 5
    Code in C++ has to be inside a function (method etc.). If you're struggling with the fundamentals, maybe it would be more practical to [read a book](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list). –  Nov 10 '21 at 12:09
  • probably needs some more brackets around the if and else clauses. (maybe also needs a "else if" ? – Max Nov 10 '21 at 12:10
  • [error message reproduced](https://godbolt.org/z/6qY8ddedx) –  Nov 10 '21 at 12:14
  • 1
    Your next problem is going to be that your second `else` is inside the `if` branch it should be the alternative to. Punctuation is important. – molbdnilo Nov 10 '21 at 12:16
  • 2
    Put your code inside of `int main()`. I assume you have declared and defined the `ungefarlika()` function. – drescherjm Nov 10 '21 at 12:19
  • 3
    By the way, 0.1 + 0.1 + 0.1 will not be the same as 0.3. Floating point does not work like that. – Bathsheba Nov 10 '21 at 12:46

0 Answers0