Using while loops - No bool. My program always divides by zero.. Any help? #include <iostream>

using namespace std;int main()

{

int value;

int leftToFactor;

int factor;cout << "Please input a value to factor: ";

cin >> value;while (value > 1) {

leftToFactor = value;

factor = 2;

while (factor <= leftToFactor){

while ((factor % leftToFactor) == 0){

cout << factor;

leftToFactor = leftToFactor / factor;

}

factor++;

}

cin >> value;

}return 0;

}

while ((factor % leftToFactor) == 0){

cout << factor;

leftToFactor = leftToFactor / factor;

}

I'm not sure what your logic is, but this loop is your problem; sooner or later,leftToFactorwill be0, and that'll cause a divide by 0 error.

I had to reverse them, I eventually figured it out.. thanks though

Ask Your Question

Weekly Poll