Hi, I'm reading Bjorne Stroustrups "Programming Principles and Practice Using C++". Right now I'm doing exercises and I'm supposed to print the prime numbers from one to hundred. I've seen a few other C++ programs that does this, but they use modulo, which I'm not supposed to have learned yet, so I have to come up with a solution without that. Also, I must use a vector to store the prime numbers.
My code is a big mess, and whenever I start it up I get memory problems and the app crashes. Any ideas on how to solve this would be very much appreciated : )
Almost forgot: the program has to use the "Sieve of Eratosthenes" method. http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
#include "../../std_lib_facilities.h"
int main()
{
vector<int>primes;
for (int i=0;i < 100; ++i){
primes.push_back(i+1);}
vector <int> not_primes;
for (int p = 2; p < 100;)
for (int not_prime = 2; not_prime < 100;)
{
not_prime += p*2;
not_primes.push_back(not_prime);
if (not_prime == 100){
for (int i = 0; i < 99; i++)
{
if (primes [i+2] = not_primes[i])
primes [i+2] = 0;
}
if (primes[p+1] != 0)
++p;
else if (primes[p+1] == 0){
for (int v = 1; primes[p+v] != 0;)
p += v;
}
}
for (int i = 0; i < 100; ++i)
{
//if (primes[i] =! 0)
cout << primes[i] << endl;
cout << not_primes[i] << endl;
}
}
keep_window_open();
}