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?

At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga.
Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus.
Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.

Get our expert's

answer on brainly

SEE EXPERT ANSWER

Get your **free** account and access **expert** answers to this

and **thousands** of other questions.

- anonymous

- katieb

See more answers at brainly.com

Get this expert

answer on brainly

SEE EXPERT ANSWER

Get your **free** account and access **expert** answers to this

and **thousands** of other questions

- anonymous

The 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

Man, It's always the little things that I miss...oh well.
I chose number three, and have implemented it.
Thanks for the help stuyboys!

- anonymous

You're welcome.

Looking for something else?

Not the answer you are looking for? Search for more explanations.

## More answers

Looking for something else?

Not the answer you are looking for? Search for more explanations.