I have a program that takes numbers entered and tells the user the total number or numbers entered and the max and the min. But then I ask the user if they would like to rerun the program and if they press yes it will run it again, but it does not clear out the index. it just keeps adding to it.
Exp. you entered 3 numbers the first time...5, 15, -5
Program will display: You entered 3 numbers.
The largest number was 15
The smallest number was -5
You select to rerun again.
You enter 3 more numbers......20, -2, 8
Program will display: You entered (6) numbers.
The largest number was 20
The smallest number was (-5)
errors in ()
here is the code I have. What do I need to do to reset it back?
const int MAX = 50;
int count = 0;
int index = 0;
char ch = 'Y';
int i = 0;
while(ch == 'Y' || ch == 'y')
cout << "Please enter a number: ";
cin >> numbers_array[index];
cout << "Do you want to enter another number?(Y/N) ";
cin >> ch;
min = numbers_array;
max = numbers_array;
while (i < count)
if (numbers_array[i] < min)
min = numbers_array[i];
else if(numbers_array[i] > max)
max = numbers_array[i];
cout << "You entered a total of " << count;
cout << " numbers." <<endl;
cout << "The largest number you entered was " << max << endl;
cout << "The smallest number you entered was " << min << endl;
cout << "Do you want to re run this program?(Y/N)";
cin >> ch;
while (ch == 'Y' || ch == 'y');