### Using For Loop

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?

 ``123456789101112131415161718192021222324252627282930313233343536`` `````` #include using namespace std; int main() { int amount; int count; int number = 0; int smallest = 999; 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 <
 ``1234`` `````` #include int smallest = intmax_t; // largest possible integer for implementation ``````

Thank you! but when I try it it wont let compile because of line 16

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970`` ``````#include #include using namespace 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 <
Sorry. Should have been:
 `` `` `` int smallest = INTMAX_MAX;``
Last edited on
Thank for helping, I appreciate it.
Topic archived. No new replies allowed.