Hello,

I've been given this algo code to rewrite in c++ :

if the list is not full then
n <- n+ 1
L[n] <- new item
else
ERROR ("List is full.")
end if

int main()
{
	int list[MAX];
	int i,n = 0;
if (n!=MAX)
{
	
for ( i = 0 ; i <MAX ;++i)
	cin >> list[n];
}
else if (n > MAX)
cout << "list is full" <<endl;


return 0;

}

but my code never prints list is full.... I've shown 3 attempts at this but not have been greated with any success.....

try this:

int main()
{
	int list[MAX];
	int t, i,n = 0;

while (cin >> t)
{
  if (n < MAX)
    list[n] = t;
  else
  {
    cout << "list is full" <<endl;
    break;
  }
  n++;
}

return 0;

}