gpt4 book ai didi

c - 函数调用的参数过多,预​​期为单个参数 'combinedValues',有 2 个参数

转载 作者:太空宇宙 更新时间:2023-11-04 08:40:46 25 4
gpt4 key购买 nike

抱歉使用了不正确的行话等等,我这周才开始学习如何编程。无论如何,在我使用的书中有一个挑战:

The interior angles of a triangle must add up to 180 degrees. Create a new C Command Line Tool named Triangle. In main.c, write a function that takes the first two angles and returns the third. Here's what it will look like when you call it:

#include <stdio.h>

// Add your new function here

int main(int argc, const char * argv[])
{
float angleA = 30.0;
float angleB = 60.0;
float angleC = remainingAngle(angleA, angleB);
printf("The third angle is %.2f\n", angleC);
return 0;
}

到目前为止我有这个:

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

// Declare a global variable?
float totalNumbers;

float remainingAngle(float combinedValues) // One argument here
{
totalNumbers = combinedValues;
float remainingAngle = combinedValues * 30.0 + 60.0;
return remainingAngle;
}

// Add new function here

int main(int argc, const char * argv[])
{
float angleA = 30.0;
float angleB = 60.0;
float angleC = remainingAngle(angleA, angleB); // Two arguments here
//Above line is giving me the error, see explanation below
printf("The third angle is %.2f\n", angleC);
return 0;
}

我遇到了错误(在以 float angleC = remainingAngle 开始的行上...在我的代码中从底部倒数第 4 个)

Too many arguments to function call, expected single argument 'combinedValues', have 2 arguments

那么,你们能告诉我如何修复我的代码吗?我是一个完全的初学者,只是问你至少告诉我如果我违反了任何不成文的规则,如何改写问题/等等以获得帮助。谢谢。

最佳答案

观察函数是如何调用的

float angleC = remainingAngle(angleA, angleB);

它接受两个参数(输入),对它们执行一些操作并返回一个输出,该输出被分配回 angleC。所以你需要相应地编码

float remainingAngle(float angleA, float angleB) //accepts two `float` arguments and returns `float` value
{
float angleC;

//sum of all angles is 180. So third angle is 180 - (sum of other two)
angleC = 180 - (angleA+angleB);
return angleC;
}

关于c - 函数调用的参数过多,预​​期为单个参数 'combinedValues',有 2 个参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23693467/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com