#2

PHOTO EMBED

Fri Dec 18 2020 04:48:24 GMT+0000 (Coordinated Universal Time)

Saved by @Javkhlantugs ##c#

            /* 
 In your code declare a variable to hold a six-digit ticket number. Ticket numbers are
 designed so that if you drop the last digit of the number, then divide the number by 7,
 the remainder of the division will be identical to the last dropped digit. This process
 is illustrated in the following example:
 a. Assign a value for the ticket number; for example, 123454.
 b. Remove the last digit, leaving 12345.
 c. Determine the remainder when the ticket number is divided by 7. In this case,
 12345 divided by 7 leaves a remainder of 4.
 d. Assign the Boolean value of the comparison between the remainder and the digit
 dropped from the ticket number. To compare two values, use the == symbol (double
 equals).
 e. Display the result - true or false –
 Test the application with the following ticket numbers:
 • 123454; the comparison should evaluate to true
 • 147103; the comparison should evaluate to true
 • 154123; the comparison should evaluate to false */


            int[] tickets = { 123454, 147103, 154123 };
            foreach (int ticket in tickets)
            {
                Console.WriteLine($"{ticket} : {((ticket / 10) % 7 ) == (ticket % 10)}");
            }

            //or 

            int ticket = 123454;
            Console.WriteLine($"{ticket} : {((ticket / 10) % 7) == (ticket % 10)}");

            int ticket1 = 147103;
            Console.WriteLine($"{ticket1} : {((ticket1 / 10) % 7) == (ticket1 % 10)}");

            int ticket2 = 154123;
            Console.WriteLine($"{ticket2} : {((ticket2 / 10) % 7) == (ticket2 % 10)}");

            //or 
            int ticket2 = 154123;
            int first5digit = ticket2 / 10; // first five digit which is 15412, leftover is 3 
            int lastdigit = ticket2 % 10; // 154123/10 leftover is 3 
            int remainder = ticket2 % 7; // leftover is 4 
            bool isValid = remainder == lastdigit;
            Console.WriteLine(isValid);
content_copyCOPY