Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 2012/5.0 > BOOK: Beginning Visual C# 2012
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning Visual C# 2012
This is the forum to discuss the Wrox book Beginning Visual C# 2012 by Karli Watson, Jacob Vibe Hammer, Jon Reid, Morgan Skinner, Daniel Kemper, Christian Nagel, ; ISBN: 978-1-118-31441-8
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Visual C# 2012 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 24th, 2013, 05:29 PM
Registered User
Points: 8, Level: 1
Points: 8, Level: 1 Points: 8, Level: 1 Points: 8, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2013
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 4 Exercise 4.2 PLEASE HELP

Okay, So I tried to do this and couldn't figure it out, I went to the appendix, and still do not understand why this is operating this way? I copied the code below with questions. If someone can maybe re paste with the answers next to each line I will greatly appreciate it!

THE QUESTION IS, Write an application that includes the logic from exercise1, obtains two numbers from the user, and displays them, but rejects any input where both numbers are greater than 10 and asks for two new numbers.

static void Main(string[] args)
{
bool numbersOK = false; //I don't understand what this is declared for
double var1, var2;
var1 = 0;
var2 = 0;

while (!numbersOK) //I don't understand what this test is performing
{
Console.WriteLine("Give me a number:");
var1 = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Give me another number:");
var2 = Convert.ToDouble(Console.ReadLine());
if ((var1 > 10) && (var2 > 10))
{
Console.WriteLine("Only one number may be greater than 10.");
}
else
{
numbersOK = true; //I don't understand why this is making it move on to the next line of code below
}
}
Console.WriteLine("you entered {0} and {1}", var1, var2);
Console.ReadKey();

Last edited by NewbySwaj; November 24th, 2013 at 05:31 PM..
  #2 (permalink)  
Old November 25th, 2013, 11:49 AM
Registered User
Points: 3, Level: 1
Points: 3, Level: 1 Points: 3, Level: 1 Points: 3, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I don't think there is anything wrong with this code it's doing exactly what it is designed to do

static void Main(string[] args)
{
bool numbersOK = false; //I don't understand what this is declared for
double var1, var2;
var1 = 0;
var2 = 0;

while (!numbersOK) //I don't understand what this test is performing
{
Console.WriteLine("Give me a number:");
var1 = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Give me another number:");
var2 = Convert.ToDouble(Console.ReadLine());
if ((var1 > 10) && (var2 > 10))
{
Console.WriteLine("Only one number may be greater than 10.");//check if both numbers are greater than 10 if so go back to the while loop and ask for new numbers because numbersOK is still false
}
else
{
numbersOK = true; // otherwise set numbersOk to true which means the while loop is false now so it gets out of the while loop and executes the next line of code after the while loop
}
}
Console.WriteLine("you entered {0} and {1}", var1, var2);
Console.ReadKey();
}

I hope this answers your question
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 4 exercise 4 earlmw BOOK: Ivor Horton's Beginning Visual C++ 2008 ISBN: 978-0-470-22590-5 0 March 3rd, 2012 03:05 PM
Chapter 8 exercise 3 Will BOOK: Beginning C# 3.0 : An Introduction to Object Oriented Programming ISBN: 978-0-470-26129-3 8 March 4th, 2010 04:15 AM
chapter 3 exercise 4 walkamongus BOOK: Beginning JavaScript 3rd Ed. ISBN: 978-0-470-05151-1 0 September 10th, 2007 09:34 PM
Chapter 3 - Exercise 3 AndyN BOOK: Beginning Cryptography with Java 3 August 16th, 2006 03:09 PM
Chapter 8, Exercise 4 cjo BOOK: Beginning ASP.NET 1.0 0 November 3rd, 2003 02:26 PM



All times are GMT -4. The time now is 07:51 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.