0

I'm writing a program that asks the user how many numbers they would like to input, then proceeds to ask the user to enter the said amount of numbers. At the end, the program computes the sum, average, largest number and smallest number. I've got the entire program figured out, but I've been sitting here for hours trying to figure out how to compute the smallest number and it's driving me crazy. Can someone please tell me how to do this? I feel like i've tried everything. (Probably not, though, seeing as I'm new to C++ lol) Here's what I have for code.

```
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
int UserInput, number, i;
int sum = 0;
float average = 0;
int largest = 0;
int smallest = 0;
cout << "How many numbers do you wish to enter? ";
cin >> UserInput;
for (i = 0; i < UserInput; i++)
{
cout << "Enter a number: ";
cin >> number;
sum = sum + number;
average = float(sum)/UserInput;
if (number > largest)
largest = number;
if (number > smallest && number < largest)
smallest = number;
}
cout << "The sum is: " << sum << endl;
cout << "The average is: " << average << endl;
cout << "The largest is: " << largest << endl;
cout << "The smallest is: " << smallest << endl;
getch();
return 0;
}
```