Program that prints prime factors needs to have them output in a specific way

I am working on an assignment to enter a number and print all the prime factors of that number. I have that working, but the assignment demands the output be formatted in a strange way which I can't figure out. For example, in my current program entering 10 gets me 25, which is actually 2 and 5. But it should get me:
( 2 * 5 )
but I can't figure out how to do this. On the chance you need it, my code is below:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
  #include <iostream>
using namespace std;
int main( )
 {
cout << "Number: ";
int number;
cin >> number;

for (int a = 2; a <= number; a++)
{
 while(number % a == 0)
 {
   number /= a;
   cout << a;
         }
         
                }
                
                        }
cout<<a<<"*";
that prints out one extra star at the end ,but you can figure the rest yourself i think
Last edited on
Thank you for your help. I did that, and it looked like the answer was obvious but I still couldn't get it. For my << cout I ended up with:
 
cout << "( " << a << "*" << " )";

which I thought would work, but when I try 10 it gives me ( 2* )( 5* ). What did I do wrong?
Hello?
Topic archived. No new replies allowed.