C++ Compute prime factors of a number and print them
<p>I want to ask the user for an integer, and print the prime factors.
Example: User enters 100, program displays 2 2 5 5</p>

<p>So far I have the following:</p>

<pre><code>#include &lt;iostream&gt;

using namespace std;

void factors(int n){

int z = 2;

while (z * z &lt;= n)
{
    if (n % z == 0)
    {   
        cout &lt;&lt; z;
        n = (n / z);
    }
    else
    {
        z++;
    }
}
if (n &gt; 1)
    {cout &lt;&lt; n &lt;&lt; "\n";}
}
int main()
{

int x;

cout &lt;&lt; "Input positive integer greater than 1: ";

cin &gt;&gt; x;

factors(x);
cout &lt;&lt; "The result: " &lt;&lt; x;
return 0;}
</code></pre>

<p>My question is how do I get my main function to communicate with the factors procedure. I run the program, I get the message asking for input, I input 12, I get the message "The result" but with a number of 25, and also 12, the number that the user input. it's like the program is avoiding my factors(int n) procedure. Help with the syntax please?!?</p>

<p>My issue is with the syntax I think.
Because I found the following function to help with listing prime factors:
<a href="https://stackoverflow.com/questions/11924249/finding-prime-factors?newreg=b54bad3fa58f42c28b3c253c17a90ac2">Finding prime factors</a>
-user44810</p>

<pre><code>define factors(n)

z = 2

while (z * z &lt;= n)

    if (n % z == 0)
        output z
        n /= z

    else
        z++

if n &gt; 1
    output n
</code></pre>

<p>Thank you!!!</p>