why wont the program terminate

so i have this program...simple thing. it just gives the base factors and every other factors to a number. it all works fine, except it wont do the last line of code and terminate. i checked all the while loops, and none of them are infinite.
here is the code

#include <iostream>
using namespace std;

int main()
{
int x, y, z;
cout << "enter number to get its factors" << endl;
cin >> y;
z = y;
x = 0;
cout << "base factors are: ";
while (y != 1)
{
x = 2;
while (y%x != 0)
{
x++;
}
cout << x << "; ";
y = y/x;
}
cout << endl;

x = 1;
cout << "normal factors are: ";
while (z != 1)
{
while (z%x != 0)
{
x++;
}
cout << x << "; ";
x++;
}
cout << " done " << endl;

return 0;
}

tell me what you think.
1
2
3
4
5
6
7
8
9
while (z != 1)
{
    while (z%x != 0)
    {
        x++;
    }
    cout << x << "; ";
    x++;
}
Where do you ever change the value of z?
hmm, thats a good point, put the loop doesnt go on. i will change the perimeters, thank you.
still didnt work, i changed it to
while (x != z)
That could cause an infinite loop too, because if X is greater than Z when it checks that, it will plow on.
Last edited on
i just figured it out. thanks for the help.

while (x < z)

basically what you said.
Topic archived. No new replies allowed.