Hi, im new to both the C++ language and this forum so bear with any of my amatuer mistakes, i have written the below code and it appears to build ok in visual studio 2005. The actual program bears no results, could someone please help me find where the problem lies; the program is supposed to factorise a number i into its prime factors (stored in vector x) then print them.
CODE
// printstl.cpp
# include <iostream > // Declares std :: cout , etc.
# include <vector > // Declares std :: vector <T >.
# include "printstl.h"
using std::cout;
using std::endl;
using std::vector;
int main(void) {
// Declare a vector to hold the prime factors.
vector <int> x;
// Declare and assign variables
i = 12;
m = i;
f = 2;
// LOOP: while m>1, if remainder of m/f is zero,
// then m=m/f and add f to vector, otherwise increase f
while(m > 1);
{
if (m%f == 0)
{
m = (m/f);
x.push_back(f);
}
else
{
f++;
}
}
cout << "Elements of x: ";
vector <int>:: iterator iter;
for ( iter = x. begin (); iter != x.end (); iter ++) {
cout << (* iter ) << " ";
}
cout << endl;
}
thank you for any replys,
lewis
This post has been edited by NickDMax: 14 May, 2007 - 07:42 AM