int Count(){
int q=1;
for (int n=3; n<=5; n++){
for (int t=2;t<n;t++){
if (n%t==0){break;}
else{ q+=1;}
}
}
return (q);
}
int main(){
cout<<Count();
return 0;
}
You are incrementing q every time n is not divisible by t. So for n = 3 you will increment q when t is 2, and for n = 5 you will increment q when t is 2, 3, and 4. Since q is initialized to 1, you get 5.