Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
BOOK: Beginning Visual C# 2010
This is the forum to discuss the Wrox book Beginning Visual C# 2010 by Karli Watson, Christian Nagel, Jacob Hammer Pedersen, Jon D. Reid, Morgan Skinner, ; ISBN: 9780470502266
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Visual C# 2010 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old May 19th, 2012, 11:43 PM
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.


Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 14 Exercise 3 and solution. UncleJeff BOOK: Beginning ASP.NET 4 : in C# and VB 2 March 14th, 2011 02:15 PM
Chapter 3 Exercise 4 Solution KurtBergman BOOK: Beginning Visual C# 2010 8 July 16th, 2010 08:13 PM
Chapter 3 - Exercise 4 - Solution gives no output Cryotic BOOK: Ivor Horton's Beginning Visual C++ 2008 ISBN: 978-0-470-22590-5 2 April 19th, 2010 08:57 AM
Chapter 13 Exercise 3 solution firblazer BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 3 April 19th, 2008 07:16 AM
Solution to exercise 7, Chapter 2 Nick Y BOOK: Ivor Horton's Beginning Visual C++ 2005 0 May 28th, 2006 04:28 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.