text: I came up with a bit of code that I think will theoretically factor any given integer within the range of integers. I'm posting this thread to ask two questions: First, is there any way that I can do this more efficiently, and second, what is the easiest way to do this using arrays. Thank you in advance for your helpful feedback, and I hope this thread can help some people (including myself) get all the more proficient at coding. So here's the code I came up with:
  #include "stdafx.h" #include <iostream> #include <string> using namespace std; int main(void) { string againloop("Yes"); do { int number; int factor(2); cout << "Please enter a number to be factored." << endl; cin >> number; cout << "The factors of your number are:" << endl; do{ if (number % factor == 0){ number = number / factor; cout << factor << endl; } else { factor++; } } while (number != 1); cout << endl << "Factor another number?" << endl; cin >> againloop; } while (againloop == "yes"||"Yes"||"YES"||"y"||"Y"); return 0; }