2
Answers

Subtracting user input

Tito Onowu

Tito Onowu

11y
921
1
Good day teachers. Am back again. Was trying to get this program to tell me how many steps has been taken from one point to the other. There should be 64 squares (A-H, 1-8)and can move from one point A to H by numerical identification.moving toward the left might be negative or from the middle downwards but all outcome regardless the sign should be positive. This is where i got and am still thinking how to make out the logic to get the right result.
Thanks.

 string pos0;
            string pos1;
            int move;

            do
            {
                Console.WriteLine(@"Enter King's position, A-H 1-8 : ");
                pos0 = Console.ReadLine().ToUpper();
            }
            while(pos0.Length != 2 ||
                !(pos0[0] >= 'A' && pos0[0] <= 'H') ||
                !(pos0[1] >= '1' && pos0[1] <= '8'));
            Console.WriteLine(@"King's position is: ");
            Console.WriteLine();


            do
            {
                Console.WriteLine(@"Enter the  position where King needs to be, A-H 1-8 : ");
                pos1 = Console.ReadLine().ToUpper();
            }
            while (pos1.Length != 2 ||
                !(pos1[0] >= 'A' && pos1[0] <= 'H') ||
                !(pos1[1] >= '1' && pos1[1] <= '8'));
            Console.WriteLine(@"King's position is: ");
            Console.WriteLine();

            move = pos0[1] - pos1[1];
            Console.WriteLine("King moved: ", move);
            Console.ReadKey (); 
Answers (2)