I am currently working on an assignment and just wanted a little help with something. For my code I have to find the lowest and highest value from an array of values, then add together the those which are not the highest or lowest (e.g, 1, 2, 3, 4, 5 --- I would add 2+3+4)
So I though the best way would be to iterate through the array and record the where the highest/lowest values are stored. This is where I a problem, the array is stored in the Main method, and I haven't found a way to access it in another method. My code so far:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Scoring {
class Program {
static void Main(string[] args) {
int[] scores = { 4, 7, 9, 3, 8, 6 };
find_Low();
ExitProgram();
}
static int find_Low() {
int low = int.MaxValue;
int low_index = -1;
foreach (int i in scores) {
if (scores[i] < low) {
low = scores[i];
low_index = i;
}
}
Console.WriteLine(low);
Console.WriteLine(low_index);
return low;
}
static void ExitProgram() {
Console.Write("\n\nPress any key to exit program: ");
Console.ReadKey();
}//end ExitProgram
}
}
The error I get is "the name 'scores' does not exist in the current context. Any tips/help would be greatly appreciated.