0

When I compile the code with inputs then it works fine. But when I want to run it with user input, it just doesn't take in inputs. It doesn't give any error.

// kefaa and first steps
// 2 2 1 3 4 1

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

int main(){
    int n, a[n], counter=0, maxIncr=0;
    cin >> n;
    cin.sync(); 
    for(int i = 0; i < n; ++i){
        cin >> a[i];
    }
    for(int i=0; i < n-1; ++i){
        if (a[i] <= a[i+1]){
            counter += 1;
            if(maxIncr<counter)
                maxIncr=counter;
        }else{
            counter=1;
        }
    }
    cout << maxIncr;
    return 0;
}
Jabberwocky
  • 40,411
  • 16
  • 50
  • 92
Divan_Cyph
  • 31
  • 5

1 Answers1

1

First of all read this about your include and why we don't include like this.

Second, if you want your program to run:

  int n; 
  cin >> n;
  int a[n], counter=0, maxIncr=0;

what you have it like @UnholySheep wrote to you, you initialize a[n] when n has not yet been assigne a value.

Jabberwocky
  • 40,411
  • 16
  • 50
  • 92
yaodav
  • 940
  • 6
  • 21