idomorad1
idomorad1

Reputation: 11

How can I make int command in boolean instead?

I want to make the same as I did here, to do the same operation, but instead of doing the int first_dig and second_dig I want to use it with boolean, something like: bool check = (new code here);

           Console.Write("Enter a two digit number: ");
            int two_dig_num = int.Parse(Console.ReadLine());
            if (two_dig_num >= 10 && two_dig_num <= 99)
            {
                int first_dig = two_dig_num % 10;
                int second_dig = two_dig_num / 10;

                if (first_dig == second_dig)
                    Console.WriteLine("YES!");

                else
                    Console.WriteLine("NO...");
            }
            else
                Console.WriteLine("\nYou haven't entered a Two Digit Number,\nPlease exit the program and try again later");
                return;
        }
    }
}

Upvotes: 0

Views: 57

Answers (1)

Markiian Benovskyi
Markiian Benovskyi

Reputation: 2161

first_dig == second_dig returns you bool, so if you want to store it in some variable then just:

bool value = first_dig == second_dig;

or with less variables it can be:

bool value = two_dig_num % 10 == two_dig_num / 10;

That is it.

Upvotes: 1

Related Questions