Click here to Skip to main content
15,902,777 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
#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;
}
Posted

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:
C
#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;
}
 
Share this answer
 
Comments
Maverick Mishra 4-Sep-14 10:40am    
thanks
CPallini 4-Sep-14 11:13am    
You are welcome.
nv3 4-Sep-14 10:41am    
Good catch! 5.
CPallini 4-Sep-14 11:13am    
Thank you.
You have declared a function with name "avg" in line 2. But further down you are referring to it by the name of "average".
C++
#include<stdio.h>
float average(float marks);
</stdio.h>

should do the trick.
 
Share this answer
 
Comments
Maverick Mishra 4-Sep-14 10:20am    
nope still doesnt work

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900