I have the following input and my program is not running: 1 3 2 1 3 7 8
#include<iostream>
#include <cstdlib>
using namespace std;
int main()
{
int arr[7], min, i=0, j=0;
for(int i=0; i<7; i++)
{
cout<<"Enter value at arr["<<i<<"]: ";
cin>>arr[i];
}
min = arr[j];
for(; i<7; i++)
{
if(arr[i] < min)
{
min = arr[i];
}
if(arr[i] == min)
{
min = arr[j+1]; //set min to next value in the array
i=j+1; //set i to value in the min + 1... program hangs here...
}
}
cout<<endl<<min;
cout<<endl<<endl;
system("pause");
return 0;
}
I think my program and the comments reflects my problem clearly... Basically my program tries to do is that when it finds a duplicate min so its set the min value to the next value in the array and set i to the next value pointed out by min so that my loop can start again and find other unique min... But my program hangs... Why?