C语言 C 编程错误:参数太少,无法运行“里面的东西”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27339250/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
C Programming Error: too few arguments to function "whatever's inside"
提问by Zan Huang
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.
这些函数应该可以工作,但为什么不行?编译器说错误:参数太少,无法运行“里面的东西”。我是 C 的初学者,所以请原谅我的愚蠢。我还想知道函数中可以包含什么。
#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();
}
回答by Pranav Totla
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 0shouldn't be allowed, et cetra.
您可能希望在代码中包含一些条件,例如0不应允许除法等。
回答by nishparadox
You havent passed any parameters to the functions.
您尚未将任何参数传递给函数。
Also, if you are intending to use global variables, dont use global names for local variables like parameters to the functions
此外,如果您打算使用全局变量,请不要对局部变量(如函数的参数)使用全局名称
eg:
例如:
add(1,2);
subtract(1,2)
Also, the part after returndoesnt get executed cuz you have returned immediately
此外,返回后的部分不会执行,因为您已立即返回
回答by Aditya Kumar
Just pass some correct values to functions while calling them. eg, when you call add(); call it like : add(5, 4)
只需在调用函数时将一些正确的值传递给函数。例如,当你调用 add(); 称之为:add(5, 4)
And, just remove void from main(void).
并且,只需从 main( void) 中删除 void 。
It will work. and do vote up if you like answer.
它会起作用。如果您喜欢答案,请投票。

