I'm just starting to learn about C++ and I converted a little program from Actionscript to C++. It's supposed to find prime numbers. The Actionscript version works perfectly, but the C++ one does not behave...
Here it is:
http://www.ampaste.net/8057
Here's the Actionscript version, if you want to compare the two:
http://www.ampaste.net/8058
The output of the C++ program:
Code:
How many prime numbers shall I find?
5
I will now find 5 prime numbers!
x % primes[0] = 3 % 2
Prime number: 3
x % primes[1] = 5 % 3
x % primes[0] = 5 % 2
Prime number: 5
x % primes[2] = 7 % 5
x % primes[1] = 7 % 3
x % primes[0] = 7 % 2
Prime number: 7
x % primes[3] = 9 % 7
x % primes[2] = 9 % 5
DEBUG: x = 11 , cycles = 0 , y = 5
x % primes[5] = 11 % 4204784
x % primes[4] = 11 % 29576745
x % primes[3] = 11 % 7
x % primes[2] = 11 % 5
x % primes[1] = 11 % 3
2
3
5
7
The program is over!
primes[5] should be
primes[3]
I don't know how
y reaches 5, because the Actionscript version only lets
y to reach 3.
I'd love to see any ways I could improve my code and any advice to solve my problem. If you have a site that you found particularly useful or want to suggest one to help me learn more about C++, go for it.
Thanks for your time!