The question:
8 children's height is being checked, and inserted.
Insert 8 double values into the console, and make an algorithm to find out the lowest height & the maximum height.
So this is what I've done:
class work1 {
public static void Main(String[] args) {
string[] height = Console.ReadLine().Split(' ');
double[] heightInDouble = new Double[height.Length];
for (int i = 0; i <= height.Length; i++) {
heightInDouble[i] = (double) height[i]; // line 20
}
Console.WriteLine("Highest: " + heightInDouble.Max() + " Lowest: " + heightInDouble.Min());
}
}
The results:
Error: Cannot convert type 'string' to 'double' (20)
How can I convert a string to a double value?
double.Parseordouble.TryParse. Look into those methods and see if that helps you. Note that if they're meant to be integers (ints) it's odd to create adoublearray. I suggest you either change the name or the type. (Actually, I'd change the name anyway to show what they're meant to be: heights.)Console.ReadLine().Split(' ').Select(double.Parse);That's if you can trust your inputs.