2017-04-28 1 views
1

좋아요. C++로 코딩 할 때 초보자입니다.이 오류를 우연히 만났을 때이 소수를 찾는 프로그램을 만들었습니다. 이것은 최고가 아니며 의견에 대해 공개적입니다. 아래 코드는 올바른 순서와 연속입니다.오류 C2660 : 함수가 2 개의 인수를 취하지 않습니다. C++

#include "stdafx.h" 

using namespace std; 

//finds prime numbers using Sieve of Eratosthenes algorithm 
vector<int> calc_primes(const int max); 

int main() 
{ 
    unsigned long long int minValue; 
    unsigned long long int maxValue; 
    bool Loop = true; 
    char chContinue; 
    vector<unsigned long long int> primes; 

    std::string Path; 
    Path = "D:\\Work\\Documents\\prime.txt"; 

    // TODO: code your application's behavior here. 
    while (Loop == true) 
    { 
     cout << "Enter minimum prime number checking range (__________)" << endl ; 
     cin >> minValue; 
     cout << "Enter maximum prime number checking range (__________)" << endl ; 
     cin >> maxValue; 
     if (maxValue <= minValue) 
     { 
      cout << "Invalid selection" << endl <<endl <<endl <<endl ; 
      continue; 
     } 

그래서 이것은 그것은 함수는 두 개의 인수를 사용하지 않는 것을 저에게 말한다 나에게 오류

 calc_primes(maxValue,primes); 

을주는 곳입니다. 그러나 선언문에는 부호없는 long long int와 unsigned long long int 벡터가 필요하다는 것이 명확하게 명시되어 있으므로 잘 모릅니다.

 //opens file path 
     std::ofstream of; 
     of.open(Path); 

     //writes to file and displays numbers 
     for(unsigned long long int i = 0; i < primes.size(); i++) 
     { 
      if(primes.at(i) != 0) 
      { 
       cout << primes.at(i) <<"  "; 
       of << primes.at(i) << "  "; 
      } 
     } 

     cout << endl <<endl <<endl <<endl ; 

     of.close(); 

     cout << "Continue? (y/n)" << endl ; 
     cin >> chContinue; 

     if (chContinue == 'y')    { 
      continue; 
     } 
     else 
     { 
      if (chContinue == 'n') 
      { 
       break; 
      } 
      else 
      { 
       cout << "Invalid Selection" << endl << endl ; 
      } 
     } 
    } 

    return 0; 
} 

이것은 함수 선언입니다. & 소수를 넣어 실수를 한 것 같습니까?

void calc_primes(unsigned long long int max, vector<unsigned long long int> &primes) 
{ 
    // fill vector with candidates 
    for(unsigned long long int i = 2; i < max; i++) 
    { 
     primes.push_back(i); 
    } 

    // for each value in the vector... 
    for(unsigned long long int i = 0; i < primes.size(); i++) 
    { 
     //get the value 
     unsigned long long int v = primes[i]; 

     if (v != 0) 
     { 
      //remove all multiples of the value 
      unsigned long long int x = i + v; 
      while(x < primes.size()) 
      { 
       primes[x] = 0; 
       x = x + v; 
      } 
     } 
    } 
} 

답변

2

함수 선언 :

vector<int> calc_primes(const int max); 

아무튼를 귀하의 기능에 일치하지 않습니다 정의는 :

void calc_primes(unsigned long long int max, vector<unsigned long long int> &primes) 

이러한 원하는 결과를 달성하기 위해 동일 할 것이다.

+0

감사합니다. 나는 초보자이다. XD – TheRealOrange

+0

도와 줘서 다행이다. –

2

이것이 이유 일 수 있습니다. 여기 :

vector<int> calc_primes(const int max); 

여기에 하나 개의 매개 변수

로 선언 그리고 당신은이 개 매개 변수를 선언 :

void calc_primes(unsigned long long int max, vector<unsigned long long int> &primes) 
관련 문제