samedi 9 novembre 2019

Can someone find the problem in my code related to IF STATEMENT in C++?

#include <iostream>
using namespace std;
int max_of_four(int q, int w, int e, int r)
{
    int x;
    if( q > w &&  q > e &&  q > r)
        {int x = q;}
    else if( w > q &&  w > e && w > r)
        {int x = w;}
    else if( e > w &&  e > q &&  e > r)
        {int x = e;}
    else if( r > w &&  r > e &&  r > q)
        {int x = r;}
    else{x = 0;}   
    return x;
}
int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max_of_four(a, b, c, d);
    return 0;
}

it always outputs 0, no matter what the input is.

I suppose the I am missing something in the if statement condition, someone please help!

Aucun commentaire:

Enregistrer un commentaire