getting false factors

I wrote a factoring program and i am getting factors plus other numbers back im not sure why i have tried using differen't loops and changing the order of the operations. help please not sure what i need to change.

[code]
#include <iostream>
#include <iomanip>
using namespace std;

int main(void)
{
int num,
factor = 2,
counter = 0;

cout << "Please Enter a Positive Number: " << endl;
cin >> num;

while ((cin.fail()) || (num < 0))
{cin.sync();
cin.clear();
cout << "Positive Numbers Only, Please Re-Enter: " << endl;
cin >> num;}


do
{
if ((num % factor)!= 0)
factor++;

else if ((num % factor) == 0)
(num = num / factor);
cout << setw (10) << factor;
counter++; factor++;
if (counter % 4 == 0)
cout << endl;

}
while (factor <= num);

cin.ignore(2);

return 0;
}
Last edited on
Use [code][/code] tags.

You need brackets around the code you want to run when the else if is hit, otherwise it runs only the next line and the rest is always run.
Topic archived. No new replies allowed.