0

While computing the sum of Leaders in an array using Visual Studio Code, I encountered an error that said: "The terminal process "C:\WINDOWS\System32\cmd.exe" terminated with exit code: 1."

My C++ implementation goes as follows:

#include<bits/stdc++.h>
using namespace std;

int leader_func(int arr[], int n)
{
  int sum=0;
  int max=arr[n-1];
  for (int i = n-2; i>=0; i--)
   {
     if (max<arr[i])
      {
         sum+=arr[i];
      }
   }
return sum;
}

int main()
{
int arr[4]={33,7,21,14};
int n=4;
cout<<leader_func(arr, n);
return 0;
}

The expected output is: 54 (i.e. 33 + 21).

The actual result I received: The terminal process "C:\WINDOWS\System32\cmd.exe" terminated with exit code: 1.

What could be the possible reasons? And how can this problem be solved?

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
  • Can't reproduce. Maybe use `#include ` instead of the dreadful `#include`? See: [Why should I not #include ?](https://stackoverflow.com/q/31816095/10871073) – Adrian Mole Jan 18 '22 at 11:14
  • ... you may be getting some kind of 'clash' between your `max` variable and something (like `std::max`?) defined in one of the zillion headers you implicitly include with that appalling first line. – Adrian Mole Jan 18 '22 at 11:17

1 Answers1

0

change project file -> settings -> post build setup -> add \ (at the end) to the xcopy message