如何纠正呼叫到非功能错误? [英] How Do I Correct Call To Non Function Error?

查看:69
本文介绍了如何纠正呼叫到非功能错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include<stdio.h>
float avg(float marks);
float percent(float marks,float total);
void main()
{
 float marks,s1,s2,s3,s4,s5,average,percentage;
 float total=500.0;

 printf("Enter the marks in five subjects");
 scanf("%f%f%f%f%f",&s1,&s2,&s3,&s4,&s5);
 marks=s1+s2+s3+s4+s5;

 average=average(marks);//says its a call to non function pls clarify//
 printf("%fAverage marks is",average);
 percentage = percent(marks,total);
 printf("%fPercentage marks is",percentage);
}
float average(float marks)
{
 float avg;
 avg=marks/5.0;
 return avg;
}
float percent(float marks,float total)
{
float p;
p=marks/total*100;
return p;
}

推荐答案

C 编程语言具有相同的命名空间对于变量和函数:这意味着你不能声明变量和具有相同名称的函数。

请尝试以下代码:

The C programming language features the same namespace for variables and functions: that means you cannot declare a variable and a function with the same name.
Try the following code:
#include<stdio.h>
float compute_average(float marks);
float compute_percent(float marks,float total);
int main()
{
 float marks,s1,s2,s3,s4,s5,average,percentage;
 float total=500.0;

 printf("Enter the marks in five subjects");
 scanf("%f%f%f%f%f",&s1,&s2,&s3,&s4,&s5);
 marks=s1+s2+s3+s4+s5;

 average=compute_average(marks);//says its a call to non function pls clarify//
 printf("Average marks is %f\n",average);
 percentage = compute_percent(marks,total);
 printf("Percentage marks is %f\n",percentage);

 return 0;
}
float compute_average(float marks)
{
 float avg;
 avg=marks/5.0;
 return avg;
}
float compute_percent(float marks,float total)
{
float p;
p=marks/total*100;
return p;
}


你已经在第2行声明了一个名为avg的函数。但是更进一步说你的名字是平均。

You have declared a function with name "avg" in line 2. But further down you are referring to it by the name of "average".
#include<stdio.h>
float average(float marks);
</stdio.h>



应该可以解决问题。


should do the trick.


这篇关于如何纠正呼叫到非功能错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆