Hi,
I would suggest you pay more attention to proper indentation, and use more
brackets, all this to make the code more readable.
Then, keep in mind that every time you execute Console.ReadLine the user has to enter something. In particular, you cannot use ReadLine twice to offer the user a choice between entering a number and entering 'done'; this must be handled with a single ReadLine.
Finally, validating user input is a must. As a result, you nearly always need to capture user input into a variable, check it, then use it.
BTW: you have a superfluous 'continue' (and you had way too many of them in an earlier problem3 too).
So my code would look more like this:
using System;
using System.Collections.Generic;
using System.Linq;
namespace ConsoleApplication1 {
class Program {
static void Main(string[] args) {
Problem4();
Console.ReadKey();
}
static void Problem4() {
List<int> evens = new List<int>();
List<int> odds = new List<int>();
int current;
string endKey = "DONE";
while (true) {
Console.WriteLine("Enter a number or 'done' to quit: ");
string input = Console.ReadLine();
if (int.TryParse(input, out current)) {
if (current % 2 == 0) evens.Add(current);
else odds.Add(current);
} else {
if (input.ToUpper() == endKey) break;
Console.WriteLine("Bad input in: " + input);
}
}
Console.WriteLine("Even average: {0}.", evens.Average());
Console.WriteLine("Odd average: {0}.", odds.Average());
}
}
}