Problem in my code?

void area(int arr[], int n)
{
stack s;
int j = 0;
int areaMax[100] = {};
for (int i = 0; i < n; i++)
{
int currentbar = arr[i];
if (s.empty() || arr[s.top()] < currentbar)
{
s.push(i);
}
else
{

			while (arr[s.top()] > currentbar)
			{
				int popBar = s.top();
				s.pop();
				if (s.empty())
				{
					areaMax[j] = arr[popBar] * i;
				}
				else
				{
					areaMax[j] = arr[popBar] * (i - s.top() - 1);
				}
				j++;
			}
			s.push(i);
	}

}
int i = n;
while (!s.empty())
{
	int popbar = s.top();
	s.pop();
	if (s.empty())
	{
		areaMax[j] = arr[popbar] * i;
	}
	else
	{
		areaMax[j] = arr[popbar] * (i - s.top() - 1);
	}
	j++;

}
for (int k = 0; k < n; k++)
{
	cout << areaMax[k] << " ";
}
cout << endl;

}

int main()
{
int arr[100] = { 6, 2, 5, 4, 5, 1, 6 };
int n = 7;
area(arr, n);
return 0;
}

I have edited your code… Try to submit it now…