need to validate input in this array code.

#include <iostream>
#include <string>
using namespace std;

int main()
{
// Declare a named constant for array size here
const int MAX_NUMS = 10;

// Declare array here
int numbers[MAX_NUMS];

// Use this integer variable as your loop index
int loopIndex;

// Use this variable to store the number input by user
int value;

// Use these variables to store the minimim and maximum values
int min, max;

// Use these variables to store the total and the average
double total, average;

// Write a loop to get values from user and assign to array
for(loopIndex = 0; loopIndex < MAX_NUMS; loopIndex++)
{
cout << "Enter a value between -1000 and 999: ";
cin >> value;
// Assign value to array
numbers[loopIndex] = value;
}
// Assign the first element in the array to be the minimum and the maximum
min = numbers[0];
max = numbers[0];
// Start out your total with the value of the first element in the array
total = numbers[0];
// Write a loop here to access array values starting with numbers[1]
for(loopIndex = 1; loopIndex < MAX_NUMS; loopIndex++)
{
// Within the loop test for minimum and maximum values.
if(numbers[loopIndex] < min) min = numbers[loopIndex];
if(numbers[loopIndex] > max) max = numbers[loopIndex];
// Also accumulate a total of all values
total += numbers[loopIndex];
}

// Calculate the average of the 10 values
average = total / MAX_NUMS;

// Print the values stored in the numbers array
for(loopIndex = 0; loopIndex < MAX_NUMS; loopIndex++)cout << "numbers[" << loopIndex << "] is: " << numbers[loopIndex] << endl;
// Print the maximum value, minimum value, and average
cout << "Minimum value is " << min << endl;
cout << "Maximum value is " << max << endl;
cout << "Average is " << average << endl;
return 0;
}
Topic archived. No new replies allowed.