C#C
C#3y ago
𝙔⁴⁴

❔ hw help

using System;
                    
public class Program
{
    public static int CountEven (int num)
    {
        int digit;
        int evencount = 0;
        while (num != 0)
        {
            digit = num % 10;
            if (num % 2 == 0)
            {
                evencount++;
            }
            num = num/10;
        }
        return evencount;
    }
    public static void Main()
    {
        int n;
        Console.WriteLine("Write how many numbers are there?");
        n = int.Parse(Console.ReadLine());
        for ( int i = 1 ; i <= n ; i++)
        {
            int c;int y = 0;int Max = 0;
            c= int.Parse(Console.ReadLine());
            Console.WriteLine( "This number has this much even numbers: " + CountEven(c));
            if (CountEven(c) > y)
            {
                y = CountEven(c);
                Max = Math.Max(y,Max);
                Console.WriteLine("This number has the most even numbers:" + Max);
            }
        }
    }
}

now i want this code to show me the number that has the most even numbers but it keeps showing me how much even numbers the numbers has instead even tho i have the max command
Was this page helpful?