I was working on a little program that would take a number as input, check if it's bigger than the variable largest and check if it's smaller than the variable smallest. Those variables were supposed to keep track of, well, the largest and smallest value entered so far.
The only problem is that both values start off holding garbage values, so I tried to assign both to zero, but when I do so the program breaks, because when I enter five for example it's supposed to be largest and smallest value but instead C++ assigns zero to the smallest value.
#include<iostream>
int main() {
double a, largest, smallest;
while (std::cin >> a) {
if (largest < a)
largest = a;
if (smallest > a)
smallest = a;
std::cout << "The smallest so far: " << smallest <<'\n';
std::cout << "The largest so far: " << largest << '\n';
}
}