Программисты помогите. Программа работает при заполнении массива рандомом, а при вводе с клавиатуры нет. C++
нужно вычислить произведение между последним максимальным и последним минимальным
# include
# include
using namespace std;
void main()
{
const int N = 100;
int mas[N];
int n, beg, end;
cout << "Enter the number of the members of the array ";
cin >> n;
while (true)
if (n > N)
{
cout << "Error enter another n ";
cin >> n;
}
else break;
bool input;
cout << "Enter random 0 Enter from the keyboard 1 ";
cin >> input;
if (input == 1)
for (int i = 0; i < n; ++i)
cin >> mas[i];
else
{
cout << "Enter the interval " << endl;
cout << "interval beginning ";
cin >> beg;
cout << "interval end ";
cin >> end;
srand(time(0));
for (int i = 0; i < n; ++i)
{
mas[i] = rand() % (end - beg) + beg;
cout << mas[i] << endl;
}
int imax = 0, max = mas[0];
for (int i = 0; i < n; ++i)
if (mas[i] >= max)
{
max = mas[i];
imax = i;
}
int imin = 0, min = mas[0];
for (int i = 0; i < n; ++i)
if (mas[i] <= min)
{
min = mas[i];
imin = i;
}
int proizv = 1;
if (imin != imax)
{
if (imin < imax)
{
for (int i = imin + 1; i < imax; ++i)
proizv *= mas[i];
cout << "proizv from min to max = " << proizv << endl;
}
else
{
for (int i = imax + 1; i < imin; ++i)
proizv *= mas[i];
cout << "proizv from max to min = " << proizv << endl;
}
}
else
cout << "Error min=max";
}
}