I can't figure out this assignment.

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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
#include <limits>
using namespace std;
const int MinInt = numeric_limits<int>::min();
const int 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
Instead of the output:

Smallest of the negative integers entered: 2137483647

I'd like it to say:

No negative integers entered.
Count the number of positive and negative numbers entered.
Change the message accordingly.
Perhaps:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>
#include <limits>

constexpr int MinInt {std::numeric_limits<int>::min()};
constexpr int 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";
}

Topic archived. No new replies allowed.