View Single Post
  #1 (permalink)  
Old May 20th, 2012, 12:43 AM
malie22001 malie22001 is offline
Authorized User
Points: 194, Level: 3
Points: 194, Level: 3 Points: 194, Level: 3 Points: 194, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2011
Posts: 41
Thanks: 0
Thanked 1 Time in 1 Post
Default Chapter 4, Exercise 2 Solution

In the book, the authors provided two solutions. They stated that the second solution is better thatn the first they provided. That made me wonder whether my solution is any better.

Code:
static void Main(string[] args)
        {
            int num1, num2;
            bool bothGreaterThan10;

            do
            {
                Console.Write("Enter your first number: ");
                num1 = Convert.ToInt32(Console.ReadLine());

                Console.Write("Enter your second number: ");
                num2 = Convert.ToInt32(Console.ReadLine());

                bothGreaterThan10 = ((num1 > 10) && (num2 > 10));

                if (!bothGreaterThan10)
                {
                    Console.WriteLine("You entered {0} and {1}", num1, num2);
                }
                else
                {
                    Console.WriteLine(@"Your both numbers are greater than 10.\n
                                        Only one number can be greater than 10.");
                }
            }
            while (bothGreaterThan10);

           

            

            Console.ReadKey();
        }
Please let me know whether I have written bad code.