Hello I'm suppose to write a program using (for loop) that asks the user to enter any amount of numbers, so that it can display the smallest and largest. My program successfully finds the largest, but I'm having trouble with
line 9:int number = 999;
although it does the job at displaying the smallest as long as one of the numbers entered has 3 digits or less , I still dont think Im doing it correct because if all the numbers I enter have more than 3 digits it will display the 999 as the smallest. Is there any way that it can be for any number entered?
#include <iostream>
#include <cstdint>
usingnamespace std;
int main()
{
int amount;
int smallest = intmax_t;// largest possible integer for implementation
int count;
int number = 0;
int largest = 0;
cout << "Enter total numbers to process: ";
cin >> amount;
for(count = 1; count <= amount; count++)
{
cout << "Enter number: ";
cin >> number;
if(number > largest)
{
largest = number;
}
if(number < smallest)
{
smallest = number;
}
}
cout << "The largest integer is " << largest <<endl;
cout << "The smallest integer is " << smallest <<endl;
system ("pause");
return 0;
}