Alex
Alex

Reputation: 107

What is causing this too few arguments error?

I am working on getting inputs from keyboard and pass them to variales in C++. I am getting too few argument error.

#include <stdio.h>
void_fullname(char fname, char lname) {
    printf("Enter Your First Name\n");
    scanf( "%d", &fname );
    printf("Enter Your Last Name\n");
    scanf( "%d", &lname );
    printf("Welcome: %d\n",First Name + Last Name)\n");
}

int main() {
    printf( "1.Full Name\n" );
    printf( "2.Exit\n" );
    scanf( "%d", &input );
    switch ( input ) {
        case 1:          
            void_fullname();
            break;
    }

    getchar();
}

Upvotes: 1

Views: 2803

Answers (4)

john
john

Reputation: 87959

It's hard to figure what you're puzzled by. You write a function with two parameters, void_fullname(char fname, char lname), you then call it with zero parameters, void_fullname();, the compiler then tells you exactly what you've done wrong. Maybe reading an introductory book on C++ will help?

I'm afraid to say there are many other errors in your code, as you'll discover once you've got the compiler errors out the way.

Here's a few tips,

1) char means a single char, not a sequence of chars. For something like a name you need a char array or a string.

2) %d is not the correct format specifier to read in character data.

3) When you wish to return data in the parameter of a function, you should pass a pointer or a reference to that function.

And so on... I think you should start with something simpler. For instance you will probably find this easier without writing any functions apart from main. Add some functions later when you've got it working without functions first. Start slowly and build up in small steps.

Upvotes: 7

Bali C
Bali C

Reputation: 31221

You're not giving void_fullname() any arguments

switch ( input ) {
    case 1:          
    void_fullname(); // Need args here
    break;

Upvotes: 1

Shiraz Bhaiji
Shiraz Bhaiji

Reputation: 65381

You are calling void_fullname without any parameters, it requires 2 parameters.

Upvotes: 0

Gabe
Gabe

Reputation: 50493

This function is expecting two arguments, fname and lname

case 1:          
    void_fullname();

Upvotes: 0

Related Questions