【发布时间】:2017-05-11 23:48:05
【问题描述】:
这是我的程序,我遇到了我不理解的语法错误。 这是我的主要接受我的功能数据:
int main() //main program
{
float num1, num2, total;
printf("Enter first number: ");
scanf("%f", &num1);
printf("Enter Second number: ");
scanf("%f", & num2);
total = multiNumbers(num1, num2);
printf("sum is %2.f", total);
return 0;
}
int multiNumbers(int num1, int num2) {
int sum;
sum = num1 * num2;
return sum;
}
以下是编译错误:
In function 'int main()':
[Error] 'printf' was not declared in this scope
[Error] 'scanf' was not declared in this scope
[Error] 'multiNumbers' was not declared in this scope
【问题讨论】:
-
这是你的整个源代码文件吗? “multiNumbers”在哪里?
-
我把我的函数放在下面.. 那不是语法行
-
您应该按照How to create a Minimal, Complete, and Verifiable example 中的说明发布整个代码——不过,现在看起来很明显
-
旁注 - 如果你想得到正确的乘法结果,你应该将
multiNumbers中的所有类型更改为float而不是int.. -
@SGH,不错的选择,但接下来就选择
double(以获得正确结果的更好机会)。float可能是大多数平台上 C 语言中最荒谬的数据类型。
标签: c function multiplication