consider this:
int count = 0;
int min = 32767;
for (i=0;i<count;i++)
{
if (number[count]<min)
min = number[count];
}//end of i
cout<<"Minimum # is"<<min<<endl;
zandiago
Nearly a Posting Maven
2,480 posts since Jun 2007
Reputation Points: 129
Solved Threads: 26
An alternate method that doesn't rely on using an array to hold each value read in and doesn't use some large number for the initial value of min would be to assign the first value entered to the variable holding smallest value entered. Then with each subsequent value entered compare it with the current smallest value and current value is smaller than current smallest value assign current value to smallest value. If you are going to use the values read in for other analyses then holding them in a container (like an array) is a good idea.
Lerner
Nearly a Posting Maven
2,382 posts since Jul 2005
Reputation Points: 739
Solved Threads: 396
Lerner
Nearly a Posting Maven
2,382 posts since Jul 2005
Reputation Points: 739
Solved Threads: 396
int main()
{
int smallest;
cout << "The firts region is the north";
smallest = getNumAccidents();
cout << "The next region is the south";
south = getNumAccidents();
findLowest(smallest, south);
cout << smallest;
}
void findLowest(int & smallest, int x)
{
//determine if x is smaller than smallest
//if so assign x to smallest
//since smallest is a reference, the current value f smallest will be retained back in main
}
int main()
{
const int MAX;
int values[MAX];
//load data into values here
int smallest;
findLowest(smallest, values);
cout << smallest;
}
void findLowest(int & smallest, int * values)
{
smallest = values[0];
for(int i = 1; i < MAX; ++i)
{
//determine if current element of values is smaller than smallest
//if so, then assign current element of value to smallest
}
}
Given the description of findLowest() using an array is probably the desired. Also, given the description of findLowest() you can declare smallest in findLowest() and not bother passing it to findLowest() since findLowest() will print it.
Lerner
Nearly a Posting Maven
2,382 posts since Jul 2005
Reputation Points: 739
Solved Threads: 396