No output produced in the c++ program

  arrays, c++

I want to write a program in c++ where consecutive elements in an array where each element in that subarray has value a[i] >= 100 are deleted and replaced by their length(of that subarray). This code does not produce any output. Can you help me find the error?

Test case :-
input – 2 100 120 3
output – 2 2 3

here consecutive values >= 100 are replaced by their length

//No output produced by the code
#include <bits/stdc++.h>
using namespace std;

void removeElements(vector<int>& array, int start, int end)
{
    array.erase(array.begin() + start, array.begin() + start + end);
}

void processArray(std::vector<int>& array)
{
    int n = array.size();
    int count = 0;
    //for(auto e: array) cout << e << " ";
    for (int i = 0; i < n; i++) {
        int temp = i;
        while (i < n && array[i] >= 100) {
            count++;
            i++;
        }
        if (count >= 2) {
            array[temp] = count;
            removeElements(array, temp + 1, temp + count);
            i -= (count - 1);
        }
        count = 0;
    }
    for (auto e : array)
        cout << e << " ";

    //return array.size();
}

int main()
{
    std::vector<int> array;
    int val;
    while (std::cin >> val) {
        if (val < 0)
            break;
        array.push_back(val);
    }
    processArray(array);
    /* for(std::vector<int>::iterator a = array.begin(); a != array.end(); a++) {
                std::cout << *a << std::endl;
            }*/
    return 0;
}

Source: Windows Questions C++

LEAVE A COMMENT