0

C Programming error: too few arguments to work & ldquo; All that is inside o...

 2 years ago
source link: https://www.codesd.com/item/c-programming-error-too-few-arguments-to-work-all-that-is-inside-of.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

C Programming error: too few arguments to work & ldquo; All that is inside of & rdquo;

advertisements

These Functions should work but why aren't they? The compiler says Error: too few arguments to function "whatever's inside". I am a beginner to C so forgive my stupidness. I would also like to know what can be in a function.

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int x;
int y;

int multiply (int x, int y)
{
    printf("()");
    return x*y;
    getchar();
    scanf("%d", &x);
    scanf("%d", &y);
    printf(":\n", multiply(x, y));

}

int add (int x, int y)
{
    printf("()");
    return x+y;
    getchar();
    scanf("%d", &x);
    scanf("%d", &y);
    printf(":\n", add(x, y));
}

int divide (int x, int y)
{
    printf("()");
    return x/y;
    getchar();
    scanf("%d", &x);
    scanf("%d", &y);
    printf(":\n", divide(x, y));
}

int subtract(int x, int y)
{
    printf("()");
    return x-y;
    getchar();
    scanf("%d", &x);
    scanf("%d", &y);
    printf(":\n", divide(x, y));
}

int power(int x, int y)
{
    printf("()");
    pow(x, y);
    getchar();
    scanf("%d", &x);
    scanf("%d", &y);
    printf(":\n", power(x, y));
}

//main code

int main(void)
{
    int option;

    switch (option)
    {
    case 1:
    add();
    break;

    case 2:
    subtract();
    break;

    case 3:
    multiply();
    break;

    case 4:
    divide();
    break;

    case 5:
    power();
    break;

    }
    getchar();
}


You are probably looking for the following code:

#include <stdio.h>
#include <math.h>

int multiply (int x, int y)
{
    return x*y;
}

int add (int x, int y)
{
    return x+y;
}

int divide (int x, int y)
{
    return x/y;
}

int subtract(int x, int y)
{
    return x-y;
}

int power(int x, int y)
{
    return pow(x, y);
}

//main code

int main(void)
{
    int option, result, x, y;
    printf("Enter the numbers:\n");
    scanf("%d%d",&x,&y);
    printf("1. Add\n2. Subtract\n3. Multiplu\n4. Divide\n5. Power\nEnter your choice:\t");
    scanf("%d",&option);
    switch (option)
    {
    case 1:
    result = add(x,y);
    break;

    case 2:
    result = subtract(x,y);
    break;

    case 3:
    result = multiply(x,y);
    break;

    case 4:
    result = divide(x,y);
    break;

    case 5:
    result = power(x,y);
    break;

    }
    printf("\nRequired result = %d",result);
    getchar();
}

You might want to include some condition in your code like division by 0 shouldn't be allowed, et cetra.

Tags function

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK