#include <iostream>
#include <string>
#include <ctime>
#include <cstdlib>
usingnamespace std;
int main()
{
int count;
int choice;
int max, min;
//asks user for amount of integers they would like to use.
cout << "Please enter the number of integers between 1 and 75 that you would like to work with: ";
cin >> choice;
// if the user doesn't enter a number from the range 1 - 75
while (choice < 1 || choice > 75)
{
cout << "Invalid Choice\n";
cout << "Please enter a number between 1 - 75: ";
cin >> choice;
}
// array to store numbers
constint ARRAY_SIZE = choice;
double number[ARRAY_SIZE];
// random
srand((unsigned)time(0));
for (count = 0; count < ARRAY_SIZE; count++)
{
number[count] = rand() %100 + 1;
cout << " " << number[count] << endl;
// maximum and minimum
if (number[count] > max) max = number[count];
elseif (number[count] < min) min = number[count];
}
// finds average
int sum = 0;
double average = 0;
for (count = 0; count < ARRAY_SIZE; count++)
{
sum += number[count];
}
average = double(sum) / ARRAY_SIZE;
// displays average
cout << "\nThe average is: " << average << endl;
cout << "\nI will give the maximum and minimum of the numbers";
//displays minimum and maximum
cout << "\n\nThe maximum is: " << max;
cout << "\nAnd the minimum is: " << min;
return 0;
}
With the users input, the program displays a random set of numbers then finds the average, maximum, and minimum of the set of numbers.
The programs builds fine, average and maximum are fine, but the minimum is always zero. Any help please?