ScrewSpurrier
Technical User
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<<"Please enter each months sales amount for the year starting with January : ";
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<<"Minimum sales is in array pos: "<<position;
getch();
}
#include <conio.h>
#include <algorithm>
void main ()
{
const int size = 12;
double array [size];
for (int i = 0; i < size; i++)
{
cout<<"Please enter each months sales amount for the year starting with January : ";
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<<"Minimum sales is in array pos: "<<position;
getch();
}