Problem with else in Dev C++

I have this code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <cstdlib>
#include <iostream>
#include <cmath>

using namespace std;

void biggest (double a, double b, double c);

int main () 
{ 
    double a, b, c;
    cout << "Enter in three values";
    cin >> a >> b >> c ;
    biggest(a,b,c);
    system ("PAUSE");
    return EXIT_SUCCESS;
}

void biggest (double a, double b, double c)
     {
             if (a > b && a > c)
             {
                   cout << "The biggest number is" << " " << a;
             }
             else (b > c && b > a)
                   ;cout << "The biggest number is" << " " << b;
                   
             else (c > a && c > b)
             {
                   cout << "The biggest number is" << " " << c;
             }
     }


For some reason the last else statement will not compile.
The error comes up as:
expected `;' before "else"
So I put the semicolon and compile again, then it comes up with the same error, so I put a semicolon after both else statements and it will not compile. Please help !!
Each else statement must have a preceding if statement. Your second else statement doesn't have an if statement.

Notice line 26 begins with a semicolon? That looks like an attempted fix for the problem of the missing "if".
So remove that semicolon as well as adding the "if".
closed account (28poGNh0)
also the else musn't have conditions

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# include <cstdlib>
# include <iostream>
# include <cmath>

using namespace std;

void biggest (double a, double b, double c);

int main ()
{
    double a, b, c;
    cout << "Enter in three values" << endl;
    cin >> a >> b >> c ;
    biggest(a,b,c);

    cin.ignore();
    return EXIT_SUCCESS;
}

void biggest (double a, double b, double c)
{
    if(a > b && a > c)
        cout << "The biggest number is" << " " << a;
    else if(b > c && b > a)
        cout << "The biggest number is" << " " << b;
    else    cout << "The biggest number is" << " " << c;
}


another also no one used Div cpp anymore use code::blocks
Last edited on
Thank you Techno01 !! You fixed my problem !
Topic archived. No new replies allowed.