im new to c++ and i am having a bit of trouble in finding lowest value. the lowest value is always returning 1 or -1 sometimes. i appreciate any help, thank you.
#include <iostream>
#include <limits>
int main()
{
constint maxScores = 5;
int scores[maxScores];
// get a number lower than the lowest possible input
int highest = std::numeric_limits<int>::min();
// get a number higher than the highest possible input
int lowest = std::numeric_limits<int>::max();
//highest = scores[0]; // the scores array filled with garbage values
//lowest = scores[0];
for (int x = 0; x < maxScores; x++)
{
std::cout << "Enter score for student " << x + 1 << ": ";
std::cin >> scores[x];
if (highest < scores[x])
{
highest = scores[x];
}
if (lowest > scores[x])
{
lowest = scores[x];
}
}
std::cout << "Highest score is: " << highest << '\n';
std::cout << "Lowest score is: " << lowest << '\n';
}
Enter score for student 1: 5
Enter score for student 2: 25
Enter score for student 3: 18
Enter score for student 4: 4
Enter score for student 5: 6
Highest score is: 25
Lowest score is: 4