Okay, also bin ich ein Anfänger in der Programmierung in C++ und ich machte diese Primzahl-Suche Programm, als ich über diesen Fehler stolperte. Das ist vielleicht nicht das Beste und ich bin offen für Feedback. Der folgende Code ist in der richtigen Reihenfolge und fortlaufend.Fehler C2660: Funktion akzeptiert nicht 2 Argumente 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;
}
Also das ist, wo es ist mir ein Fehler
calc_primes(maxValue,primes);
Es sagt mir, dass die Funktion nicht zwei Argumente nicht statt. Allerdings gibt die Deklaration eindeutig an, dass sie einen vorzeichenlosen langen langen int und einen Vektor von unsigned long long int benötigt, also bin ich mir nicht sicher.
//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;
}
Dies ist die Funktionsdeklaration. Glaubst du, ich habe einen Fehler gemacht, indem ich & Primzahlen gesetzt habe?
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;
}
}
}
}
danke! Ich bin wirklich ein Anfänger XD – TheRealOrange
Gern geschehen, froh zu helfen. –