I think I have managed to solve this but want to make sure

Code:

#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int n;
double m;
int i = 2;
int isPrime = true;
cout << "Please enter a number and press enter " ;
cin >> n;
cout << endl;
m = sqrt(double(n));
cout << m;
cout << endl;
while (i <= m) // or (i*i<=n)
{
if (n % i == 0)
isPrime = false;
break;
}
i++;
if (isPrime)
cout << "Number is a prime number" << endl;
else
cout << "Number is not a prime number" << endl;
}

So what this is doing if I am correct, is calculating the square root of int n only once, then as long as double m is less than or equal to int i, it will keep looping, is this code right ?????