Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
BOOK: Beginning C# 6.0 Programming with Visual Studio 2015
This is the forum to discuss the Wrox book Beginning C# 6.0 Programming with Visual Studio 2015 by Benjamin Perkins, Jacob Vibe Hammer, Jon D. Reid; ISBN: 978-1-119-09668-9
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning C# 6.0 Programming with Visual Studio 2015 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 November 13th, 2016, 11:18 AM
Registered User
Points: 5, Level: 1
Points: 5, Level: 1 Points: 5, Level: 1 Points: 5, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2016
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Post Chapter 11 Example 3 code error

When reading through the example, I input exactly the same code as the example shows, and run the program. But the result showed every number from 2 to 1000, while the program is meant to show all primes between 2 and 1000. There must be some code error given by the example. Is there anyone who also found it? And How to correct the code here?
  #2 (permalink)  
Old March 26th, 2017, 04:17 PM
Registered User
Points: 12, Level: 1
Points: 12, Level: 1 Points: 12, Level: 1 Points: 12, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2017
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Reply

Hi,

I am not sure if you are still looking for an answer.

The coder as written will check the lower and upper. The reason these get checked is the following line of code:

Code:
for(long possiblePrime=min;possiblePrime <=max;possiblePrime++)
This sets and loops through the candidate prime list. It starts with the min value (set to 2 in example) and finishes with 1000 (including 1000 because of the <= test).

If you didn't want to include 2 and 1000, you could change the code to:
Code:
for(long possiblePrime=min+1;possiblePrime <max;possiblePrime++)
This would eliminate the lower bound by starting with one larger than it and the upper bound by stopping before testing it.

Michael


Similar Threads
Thread Thread Starter Forum Replies Last Post
Where is the code for Chapter 11 ? Jim Schmit BOOK: Professional Visual Studio 2015 0 September 24th, 2016 07:57 PM
Runtime Error from Chapter 11 Code winkle BOOK: Expert Access 2007 Programming ISBN 978-0-470-17402-9 1 April 22nd, 2009 02:41 PM
Error in Chapter 11 Sample Code josevi BOOK: Professional SharePoint 2007 Development ISBN: 978-0-470-11756-9 1 February 1st, 2008 01:43 PM
Chapter 11 Code Problems vbswshare BOOK: Professional VB 2005 ISBN: 0-7645-7536-8 3 April 9th, 2006 08:39 PM





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