Проблема кода в плохом отступе.
for (int i = 0; i < SIZE; i++)
{
if (cin >> userinput[i])
{
count++;
}
else
{
break;
}
while (count < userinput[i])
{
if (largest < userinput[i])
{
largest = userinput[i];
}
count++;
}}
Пока l oop находится внутри для l oop. И это условие пока l oop
count < userinput[i]
не имеет смысла.
Разделите циклы.
for ( size_t i = 0; i < SIZE; i++ )
{
if (cin >> userinput[i])
{
count++;
}
else
{
break;
}
}
int largest = count == 0 ? 0 : userinput[0];
for ( size_t i = 1; i < count; i++ )
{
if ( largest < userinput[i] )
{
largest = userinput[i];
}
}
Примите во внимание, что вы можете использовать стандартный алгоритм std::max_element
, объявленный в заголовке <algorithm>
Например,
auto it = std::max_element( userinput, userinput + count );
if ( it != userinput + count ) largest = *it;
Функция printarray
может быть объявлена и определена как
std::ostream & printarray( const int array[], size_t size, std::ostream &os = std::cout )
{
for ( size_t i = 0; i < size; i++ )
{
os << array[i] << ' ';
}
return os;
}
Обратите внимание, что нигде в вашей программе не выводится самый большой элемент.