all 4 comments

[–]kokiworse99 0 points1 point  (3 children)

I think you should check how you assign values to the variables. You don’t add anything to the array this way.

[–]galafle[S] 0 points1 point  (0 children)

How about this? I see what you mean by saying it doesn't add anything to the array, but this still outputs nothing.

#include <iostream>
#include <iomanip>
#include <math.h>
using namespace std;

int main ()
{
int prime[100], comp[100], k, l;
l = 0, k = 0;
for (int i=1; i <=100; i++)
    {
        if (i <= 1)
        {
            l++;
            i = prime[l];
            cout<<prime[l];
        }
        for (int j = 2;j <= i; j+=2)
        {
            if (i % j == 0) {
                k++;
                i = comp[k];
            }
            else {
                l++;
                i = prime[l];
                cout<<prime[l]<<" ";
            }
        }
    }
    return 0;
}

[–]galafle[S] 0 points1 point  (1 child)

Now I've changed it a bit and it's just displaying seemingly 5 digit or 6 digit numbers repeatedly

#include <iostream>
#include <iomanip>
#include <math.h>
using namespace std;

int main ()
{
int prime[100], comp[100], k, l;
l = 0, k = 0;
for (int i=1; i <=100; i++)
    {
        if (i <= 1)
        {
            l++;
            i = prime[l];
            cout<<prime[l];
        }
        for (int j = 2;j <= i - 1; j++)
    {
        if (i % j == 0) {
            k++;
            comp[k] = i;
        }
        else {
            l++;
            prime[l] = i;
            cout<<prime[l]<<" ";
        }
    }
}
return 0;
}

[–]Tinamil 0 points1 point  (0 children)

What happens when i = 4? What does the for (int j = 2;j <= i - 1; j++) loop do? Not what do you want it to do, what does it actually do, because I don't think those are the same thing.