How would I go about making a different message appear when no positive integers or negative integers are entered, instead of it showing a really large or small number? This is what I've got so far:
#include <iostream>
#include <limits>
usingnamespace std;
constint MinInt = numeric_limits<int>::min();
constint MaxInt = numeric_limits<int>::max();
int main()
{
int number, sum = 0, smallest = MaxInt, largest = MinInt;
cout << "Enter integers and when done enter 0: ";
while (cin >> number)
{
if (number == 0)
break;
if (number > 9 && number < 100 or number > -100 and number < -9)
sum += number;
if (number > largest and number > -1)
largest = number;
if (number < smallest and number < 1)
smallest = number;
}
cout << "Smallest of the negative integers entered: " << smallest << "\n";
cout << "Largest of the positive integers entered: " << largest << "\n";
cout << "Sum of all double digit integers: " << sum << "\n";
}
Input:
1 2 3 4 5
1
2
3
4
0
Output:
1 2 3
Smallest of the negative integers entered: 2147483647
Largest of the positive integers entered: 4
Sum of all double digit integers: 0
#include <iostream>
#include <limits>
constexprint MinInt {std::numeric_limits<int>::min()};
constexprint MaxInt {std::numeric_limits<int>::max()};
int main() {
int sum {}, smallest {MaxInt}, largest {MinInt};
std::cout << "Enter integers and when done enter 0: ";
for (int number {}; std::cin >> number && number; ) {
if (number > 9 && number < 100 or number > -100 and number < -9)
sum += number;
if (number > largest and number > -1)
largest = number;
if (number < smallest and number < 1)
smallest = number;
}
if (smallest != MaxInt)
std::cout << "Smallest of the negative integers entered: " << smallest << "\n";
else
std::cout << "No negative integers entered\n";
if (largest != MinInt)
std::cout << "Largest of the positive integers entered: " << largest << "\n";
else
std::cout << "No positive integers entered\n";
std::cout << "Sum of all double digit integers: " << sum << "\n";
}