错误"调用过载' sqrt(int&)'

时间:2017-08-23 22:11:48

标签: c++ cmath

enter image description here

所以我刚开始用C ++阅读这本书" C ++而不用担心第二版"我正在做一个让我写这段代码的例子:

#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;

}

然而,当我尝试编译时,我得到了错误

  

14 C:\ Users \ Owner \ Desktop \ C ++ \ PrimeCheck.cpp   调用重载的`sqrt(int&amp;)&#39;

0 个答案:

没有答案