I'm going through some practice for arrays (let me specify this is NOT homework i just completed a test which i know in my soul i failed and i'm practicing) and performing functions on them and I'm running into this problem. My method for finding highest number, average, and total works but, find the lowest number isn't and I'm honestly stuck as to why.
To explain my array: index 0 is where i want to store my highest number index 1 is where i want to store my lowest number
my method starts at index 2 to find lowest / highest numbers since the lowest / highest would be store in the first two element of the array. my array size also takes this into concideration as well as the file reader, they all start at index 2.
I've also tried value returning methods while still getting the same end result.
Below are the methods i've tried that aren't putting out the desired information:
this method assigns highest to salesArray[0] and lowest to salesArray1, and accomodates array size and array read starts at 2.
private void Lowest()
{
//method variables
double lowest = salesArray[1];
//find lowest sale
for (int index = 2; index < salesArray.Length; index++)
{
if(salesArray[index] < lowest)
{
lowest = salesArray[index];
}
}
This way I used making both highest/lowest index 0 to try what was suggest in a previous comment:
private void Lowest()
{
//method variables
double lowest = salesArray[0];
//find lowest sale
for (int index = 1; index < salesArray.Length; index++)
{
if(salesArray[index] < lowest)
{
lowest = salesArray[index];
}
This is the value returning method I tried:
private double Lowest(double[] salesArray)
{
//method variables
double lowest = salesArray[0];
//find lowest sale
for (int index = 1; index < salesArray.Length; index++)
{
if (salesArray[index] < lowest)
{
lowest = salesArray[index];
}
}
return lowest;
}