I am trying to count the number of prime divisors for example prime divisors of 20 is 2*2*5 which is 3. The number of primes seem to be right sometimes.

Code:

#include <iostream>
#include <cmath>
using namespace std;
void prime_divisor(int n){
int d=2;
while(d<=sqrt(n)){
if(n%d==0){
cout<<d<<"*";
n=n/d;
continue;
}
++d;
}
cout<<n<<endl;
}
int prime_decomposition_r(int n){
int count=0;
for(int d=2; d<=sqrt(n); ++d){
if(n%d==0){
++count;
}
}
return count;
cout<<count<<endl;
}
int main(){
int n=0;
cout<<"n: ";
cin>>n;
cout<<"Type a positive integer:"<<n<<endl;
cout<<n<<"=";
prime_divisor(n);
cout<<"There are "<<prime_decomposition_r(n)<<" prime factors.";
}