A community for students.
Here's the question you clicked on:
 0 viewing
anonymous
 5 years ago
I am entering my code for problem set 1 problem 1, (
http://pastebin.com/nzG9Nva7,
under v:3.0), and recieve 7921 instead of what it should be (which is 7919). Can someone point me in the right direction as to what I'm doing wrong?
anonymous
 5 years ago
I am entering my code for problem set 1 problem 1, ( http://pastebin.com/nzG9Nva7, under v:3.0), and recieve 7921 instead of what it should be (which is 7919). Can someone point me in the right direction as to what I'm doing wrong?

This Question is Closed

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0The error is with your code at line 57 prime_number_candidate=prime_number_candidate+2 So even though your loop ends at the correct iteration, you actually incremented prime_number_candidate before the last iteration ends. That's why you get your last prime number (7919) + 2. There are several ways to solve this, however each solution have different merits/faults. 1. subtract 2 from your prime_number_candidate after you exit the outer while loop. To get your last prime number. 2. use another variable (lastPrime) to store the last prime number found (not the next prime_number_candidate), and print the variable lastPrime . 3. initialize your loop differently such that you increment prime_number_candidate as the first (or one of the first) instructions in your outer while loop. This would cause prime_number_candidate to be equal to the prime number (if the number is prime).

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0Man, It's always the little things that I miss...oh well. I chose number three, and have implemented it. Thanks for the help stuyboys!
Ask your own question
Sign UpFind more explanations on OpenStudy
Your question is ready. Sign up for free to start getting answers.
spraguer
(Moderator)
5
→ View Detailed Profile
is replying to Can someone tell me what button the professor is hitting...
23
 Teamwork 19 Teammate
 Problem Solving 19 Hero
 Engagement 19 Mad Hatter
 You have blocked this person.
 ✔ You're a fan Checking fan status...
Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.