Skip to content

Instantly share code, notes, and snippets.

@bigworld12
Created March 31, 2017 19:29
Show Gist options
  • Save bigworld12/7f6d5ebac77c4593411f86e27e77d5f6 to your computer and use it in GitHub Desktop.
Save bigworld12/7f6d5ebac77c4593411f86e27e77d5f6 to your computer and use it in GitHub Desktop.
class Program
{
static void Main(string[] args)
{
MyClass odd_c = new MyClass();
MyClass even_c = new MyClass();
while (true)
{
int user_input = int.Parse(Console.ReadLine());
if (user_input == 0)
{
break;
}
if (user_input % 2 == 0)
{
even_c.add(user_input);
}
else
{
odd_c.add(user_input);
}
}
odd_c.output("odd numbers");
even_c.output("even numbers");
Console.ReadKey();
}
}
public class MyClass
{
int sum, count;
float avg;
public MyClass()
{
sum = 0;
count = 0;
}
public void add(int num)
{
sum += num;
count++;
}
public void output(string name)
{
avg = (float)sum / count;
Console.WriteLine("average of {0} : {1}", name, avg);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment