I am writing a C++ code that lets the user enter 10 values into an array. The program should then display the largest and smallest values stored in the array. My code so far completes these requirements, however, when running the code, no matter which numbers are input, the program returns -858993460 as the smallest number in the array. The largest number however, is returned without any issues. I have rewritten the code from scratch twice now with the same problem. Using Visual Studio to compile. Thanks for the help.
#include <iostream>
using namespace std;
int main()
{
int numbers[10];
int smallest = 0;
int largest = 0 ;
int temp = 0;
for (int i = 0; i < 10; i++)
{
cout << "Please enter a number: " << endl;
cin >> numbers[i];
}
smallest = numbers[0];
largest = numbers[0];
for (int i = 1; i <= 10; i++)
{
temp = numbers[i];
if (temp < smallest)
smallest = temp;
if (temp > largest)
largest = temp;
}
cout << "The largest number is: " << largest << endl;
cout << "The smallest number is: " << smallest << endl;
}