Just tried to make a quick prime number checker:

#include <iostream>
#include <cmath>
using namespace std;

void askForNumber();
bool checkPrime();
void printPrime();
void printNotPrime();

int numberEntered;
int x = 2;
bool isPrime = true;

int main(){
    askForNumber();
    if(checkPrime(numberEntered) == true){
                                 printPrime();
    }
    else{
         printNotPrime();
    }
    return 0;
}

void askForNumber(){
     cout << "Enter a number to see if it is prime: ";
     cin >> numberEntered;
}

bool checkPrime(int enteredNumber){
     while(x < sqrt(enteredNumber)){
             if(enteredNumber % x == 0 && enteredNumber != x){
                 return false;
             }
             x++;
     }
}

void printPrime(){
     cout << numberEntered << " is prime!";
}

void printNotPrime(){
     cout << numberEntered << " is not prime.";
}

I don't need help making it work, just the errors I get at line 6 and 16:

6: 'too many arguments to function `bool checkPrime()'
16: 'at this point in file'

Thanks.

Dani AI

Generated

is correct: the compiler error comes from a mismatch between the function prototype and the function call/definition. The line that declares checkPrime with no parameters tells the compiler it expects zero arguments. Later you call checkPrime(numberEntered) and then define checkPrime with a parameter — those must agree, or the compiler emits "too many arguments" and a follow-up "at this point in file" when it finds the conflicting declaration.

Fixes to apply (small, safe changes):

  • Make the prototype and definition match. The parameter name in the prototype is optional, but the types and number of parameters must be identical.
  • Ensure the function actually returns true when appropriate; a non-void function must return on all control paths.
  • Prefer local loop variables instead of a global x, and avoid repeated calls to sqrt with floating-point comparisons (use integer checks).

Example of a clean, corrected checkPrime pattern:

bool checkPrime(int n); // prototype

bool checkPrime(int n) {
    if (n < 2) return false;
    if (n == 2) return true;
    if (n % 2 == 0) return false;
    for (int i = 3; i * i <= n; i += 2)
        if (n % i == 0) return false;
    return true;
}

Additional notes: reset any stateful globals (or better, drop them entirely), handle small inputs (0 and 1) explicitly, and compile with warnings enabled (for example -Wall -Wextra with g++) to catch "control reaches end of non-void function" and prototype mismatches early. For the immediate error, change the forward declaration to include the int parameter (or remove the argument at the call), and the compile error should go away.

The function declaration and the function don't match. The function takes a parameter, but the function declaration says it doesn't. Copy line 30 to line 6. Lines 6, 16, and 30 need to match each other as far as the parameters the function takes.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.