15,310,682 members
See more:
the code does not get build
the code is to find sum and average of 2 numbers using functions

What I have tried:

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

int main (){
float a,b;
printf("Enter the tow numbers whose sum and average are needed\n");
scanf("%lf",&a);
scanf("%lf",&b);
printf("The sum is %f\n",sum(a,b));
printf("The average is %f\n",average(a,b));
}
float sum(float a ,float b){
float sum=a+b;
return sum;
}
float average(float a,float b){
float average=(a+b)/2;
return average;
}```
Posted
Updated 4-Jul-21 20:21pm
v2
Patrice T 4-Jul-21 11:16am

Try to give error messages.

## Solution 2

The major problems of your program are the missing function prototypes.
I've fixed the code for you
C
```#include<stdio.h>
#include<stdlib.h>

float sum(float a, float b);
float average(float a, float b);

int main ()
{
float a,b;
printf("Enter the tow numbers whose sum and average are needed\n");
scanf("%f",&a);
scanf("%f",&b);
printf("The sum is %f\n",sum(a,b));
printf("The average is %f\n",average(a,b));
return 0;
}

float sum(float a, float b)
{
float sum = a + b;
return sum;
}

float average(float a, float b)
{
float average = ( a + b ) / 2;
return average;
}```
[no name] 8-Jul-21 3:07am

Thank u
CPallini 8-Jul-21 3:09am

You are welcome.

## Solution 1

Quote:
the code does not get build

Means very little to us without actual error messages ... and we can't see your screen, we have no idea what compiler you are using, we can't read your mind!

But ... "%lf" as a `printf` format expects a pointer to a `double` not a `float` - so some compilers will complain. I'd suggest changing "float" to "double" throughout.

And you haven't declared your functions before you try to call them - and all compilers will complain about that! See here: Forward declaration - Wikipedia[^]

Do yourself a favour: look at error messages and try to work out what you did wrong from that - they tell you the line number (at the very least) that the problem was discovered on. Learning to do this yourself will save you a huge amount of time for very little effort - you will be getting compiler errors for a very, very long time! (I've be writing software for over 40 years, and I still get them!)
Relying on others to fix them for you will take considerably longer than doing it yourself, as nobody is going to respond immediately ....
[no name] 8-Jul-21 3:07am

Thank u guy (who has been writing code for last 40 years) .
also I started to code 40 days ago and its the first question I have ever asked online so,