Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 6 > BOOK: Beginning C# 6.0 Programming with Visual Studio 2015
Password Reminder
Register
Register | FAQ | Members List | Calendar | 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 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
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old November 13th, 2016, 10: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?
Reply With Quote
  #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
Reply With Quote
Reply


Thread Tools
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
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 12:43 PM
Chapter 11 Code Problems vbswshare BOOK: Professional VB 2005 ISBN: 0-7645-7536-8 3 April 9th, 2006 08:39 PM



All times are GMT -4. The time now is 01:16 AM.


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