我正在尝试编写一个简单的逻辑程序来找到已经完成的最高和最低值。问题是如何找到索引位置是当它找到最高和最低值时。见附图。
#include <iostream>
using namespace std;
int main()
{
int number=0, min=0, max=0;
int *rangeOfNumbers = new int[];
cout<<"Enter 5 numbers: ";
for(int i=0; i<5;i++)
{
cout<<"Enter number "<<i+1<<": ";
cin>>rangeOfNumbers[i];
}
//max min array positions
min=rangeOfNumbers[0];
max=rangeOfNumbers[0];
//find max and mins
for(int j=0; j<5;j++)
{
if(max<rangeOfNumbers[j])
{
max=rangeOfNumbers[j];
}
else if(min>rangeOfNumbers[j])
{
min=rangeOfNumbers[j];
}
}
cout<<"\n\nMin number: "<<min;
cout<<"\nMax number: "<<max;
cin.get();
cin.get();
return 0;
}