I wrote this code for finding out if a number entered is a prime number or a perfect square. It only works if the number entered is a perfect square already. all else totally fails.

0----------------------------------

#include <iostream>

#include <iomanip>

void main()

{

int num;

bool prime = true;

cout << "Enter a number" << endl;

cin >> num;

for (int p=1; p < num; p++)

{

if ( num % p == 0 )

{

prime = false;

if (p * p == num )

{

cout << num << " is a perfect square. Its square root is " << p << endl<<endl;

}

}

}

if ( prime )

cout << num << " is a prime number."<<endl<<endl;

}

---------END

Any ideas?