Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

array position

Status
Not open for further replies.

ScrewSpurrier

Technical User
Feb 10, 2003
7
0
0
US
I am trying to get cout the array value of the smallest value in the array. I have come up with the code below but I always get the awnser 0. I am not sure why as I think my postion should increment by one if smallest number is not found since it is in the loop. Any help would be greatly appreciated.

#include <conio.h>
#include <algorithm>
void main ()
{
const int size = 12;
double array [size];

for (int i = 0; i < size; i++)
{
cout<<&quot;Please enter each months sales amount for the year starting with January : &quot;;
cin>>array;
}
double minimum;
minimum = array[0];
int position = -1;

for (int j = 0; j < size; j++)
{
if(array [j] < minimum)
position = position + 1;

}
cout<<&quot;Minimum sales is in array pos: &quot;<<position;

getch();
}
 
Alright I have now changed my loop to this which I think will solve my problem but I am getting an illiegal structure error on my cin>>;

Any suggestions?
 
oops..
To this..
------------------------------------------
position = 0;
for( int j = 0; j < size; j++ )
{
if( array[j] < array[position] )
position = j;
}
------------------------------------------
 
It's TGML. Uncheck the &quot;Process TGML&quot; box before you post, and you can type: .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top