help me

I think I may mistake myself. For my homework. Here
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
#include <cmath>

using namespace std;

int main() {
    int n;
    int i;
    int is_prime = true;
    
    cout << "Enter a number and press Enter: ";
    cin >> n;
    
    i = 2;
    while (i <= sqrt(n)) {
        if (n % i == 0)
            is_prime = false;
        i++;
    }
    
    if (is_prime)
        cout << "Number is prime." << endl;
    else
        cout << "Number is not prime." << endl;
        
    system("pause");
    return 0;
}


Please fix for me. Thanks
People generally aren't just gonna FIX your code for you...especially if they have no idea what you are asking?

1st - I ran the code just out of curiosity and I see nothing wrong with it...seems to report things correctly.

2nd - I think a proper way to call is_prime would be with "bool" - may want to look up for more clarification (bool = true/false answers vs int which wants to assign numbers).

So what is the problem here?
Number 15 is error. It is said that C:\Users\Duy N. Le\Desktop\C++\prime1.cpp
call of overloaded `sqrt(int&)' is ambiguous
Oh never mine. I found it. http://v2.cplusplus.com/forum/beginner/61858/ =]
Topic archived. No new replies allowed.