jeudi 25 avril 2019

Why is my program is outputting '0' when run, when it is not supposed too?

I am quite new to c++, and was just playing around with if statements, so I made this program:

#include <iostream>
using namespace std;
int getMax(int num1, int num2){

    if (num1>num2)
    {
        cout << num1 <<endl;
    }else{
        cout << num2 <<endl;
    }
    return EXIT_SUCCESS;
}

int main(){
    cout<<getMax(7,13)<<endl;

    return 0;
}

My getMax function takes two parmeters and is supposed to output the greater of the 2 numbers — in this case 13. But instead of only outputting 13, it also outputs 0. Why is this happening?

Aucun commentaire:

Enregistrer un commentaire