C 错误:参数太少,无法正常工作?

C 错误:参数太少,无法正常工作?,c,C,我在代码的另一部分做了完全相同的事情,但在这一部分中,它的工作方式没有错误或任何问题,所以它给了我一个错误。 所以函数是 void triangle(int height,int base) { printf("Enter the base of the triangle:"); scanf("%d",&base); printf("\nEnter the height of the triangle:"); scanf("%d",&height);

我在代码的另一部分做了完全相同的事情,但在这一部分中,它的工作方式没有错误或任何问题,所以它给了我一个错误。 所以函数是

void triangle(int height,int base)
{
   printf("Enter the base of the triangle:");
   scanf("%d",&base);
   printf("\nEnter the height of the triangle:");
   scanf("%d",&height);
   int area;
   area = (height*base)/2;
   printf("\nTriangles area is %d.",area);
}
void triangle(int height,int base)
{
   printf("Enter the base of the triangle:");
   scanf("%d",&base);
   printf("\nEnter the height of the triangle:");
   scanf("%d",&height);
   int area;
   area = (height*base)/2;
   printf("\nTriangles area is %d.",area);
}
我在代码中使用了switch case函数,这就是我在main函数中调用它的方式

case 3:
     {
         triangle(area);
     }
感觉怪怪的,但这很好用

void square(int length)
{
printf("Enter the length of square:");
scanf("%d",&length);
int area;
area = length*length;
printf("\nRectangles area is %d.",area);
}
像这样,

case 1:
        {
            square(area);
        }
我在代码的另一部分做了完全相同的事情,没有出现错误或错误 它的工作方式有任何问题,但在这一部分,它给出了 我犯了个错误

C不保证在编译时或运行时诊断所有不正确的代码。不过,您应该提高编译器的警告级别。如果之后,它在任何地方都接受了对
triangle()
函数的调用,而不是两个参数,并且至少没有发出某种警告,那么就把它扔掉,选择一个更好的

所以函数是

void triangle(int height,int base)
{
   printf("Enter the base of the triangle:");
   scanf("%d",&base);
   printf("\nEnter the height of the triangle:");
   scanf("%d",&height);
   int area;
   area = (height*base)/2;
   printf("\nTriangles area is %d.",area);
}
void triangle(int height,int base)
{
   printf("Enter the base of the triangle:");
   scanf("%d",&base);
   printf("\nEnter the height of the triangle:");
   scanf("%d",&height);
   int area;
   area = (height*base)/2;
   printf("\nTriangles area is %d.",area);
}
请注意,函数实际上并不使用调用者为任一参数提供的值,也不会以任何方式向调用者返回任何信息,即使您使用正确数量的参数调用它。如果这是您想要的,那么最好声明它不接受任何参数,并这样称呼它:

void triangle(void) {
    int length;
    int height;
    // ...
请注意,
length
height
现在是严格的局部变量。你这样称呼这种变化:

triangle();

你以为会发生什么?您的
三角形
函数接受两个参数(
高度
基础
),但调用它时只传递一个(
面积
)。函数需要两个参数,而您传递一个?这就是问题所在吗?看看你的函数定义:空心正方形(整数长度)和空心三角形(整数高度,整数基数)。调用函数时,必须提供括号中的内容。考虑到如何编写这些函数的内容,您可能希望使用局部变量,而不是传递参数。然而,
break多少个案例?