Why MingW is compiling wrong?

  c++, compiler-construction, ide, mingw, visual-studio-code

I have been learning C++ using VS Code as the IDE and MingW as the compiler. While writing a code I encountered a problem where the output I got didn’t matched with what I expected it to be. Here’s the code I wrote :

#include<iostream>
using namespace std;

int sum(int a, int b){
    cout<<"Using function with 2 arguments"<<endl;
    return a+b;
}

int sum(int a, int b, int c){
    cout<<"Using function with 3 arguments"<<endl;
    return a+b+c;
}

int main() {
    cout<<"The sum of 3 and 6 is "<<sum(3,6)<<endl;
    cout<<"The sum of 3, 7 and 6 is "<<sum(3, 7, 6)<<endl;

    return 0;
}

The output I got was this :

using function with 2 arguments 
The sum of 3 and 6 is 9
using function with 3 arguments
The sum of 3, 7 and 6 is 16

But I believe the output should be :

The sum of 3 and 6 is Using function with 2 arguments   
9
The sum of 3, 7 and 6 is Using function with 3 arguments
16

I tried copy pasting it on a online editor and it did worked there correctly. Is there some issue with my compiler ? If yes, then how can I fix it ?

Source: Windows Questions C++

LEAVE A COMMENT