How to drop last digit from a number in c#

Hi guys,

I am trying to make this program with a variable that takes a 6 digit number and then drop the last digit. once that is done i need to get the remainder of the second number devided by 7 and then compare that to the dropped digit. Below you can find a code snippet where i put whatever it’s in my head. This is in C# which i am new to and i would appreciate the help.
Thanks

    class Program
    {
        static void Main(string[] args)
        {
            int ticketNumber = 123454;
            int newNumber= (I don't know);
            int remainder = newNumber %  7;
            bool compared = (remainder == droppedNumber);


            Console.WriteLine(compared);
        }
    }
}

To get the last digit of a number, you need to modulo the number by 10.
To drop the last digit of a number, you need to divide the number by 10.

class Program
{
    static void Main(string[] args)
    {
        int ticketNumber = 123454;
        int droppedNumber = ticketNumber % 10;
        int newNumber= ticketNumber/ 10;
        int remainder = newNumber %  7;
        bool compared = (remainder == droppedNumber);


        Console.WriteLine(compared);
    }
}

I hope this will help you solve the issue.

1 Like

Legend @oddcoder Thanks you very much for the quick reply. that solved my problem :+1: