15,617,168 members
1.00/5 (1 vote)
See more:
My function is not calculating the expected value instead printing some negative integers as result.

What I have tried:

```// code to find area of rectangle using functions
#include<stdio.h>
#include<stdlib.h>

// function for calculating the area of rectangle
float areaofrect(float l,float b)
{
float area;
area=l*b;
return area;
}

//Driver function
int main()
{
float a,b,A;
printf("enter length,breadth of the rectangle:");
scanf("%f,%f",&a,&b);
A=areaofrect(a,b);
printf("the area of the rectangle is:%f",A);
return 0;
}```
Posted
Updated 22-Oct-21 22:41pm
v2

## Solution 1

It works fine for me: I paste your code into on online compiler, and enter two numbers. I get the result I expect:
```enter length,breadth of the rectangle:2.0,3.3
the area of the rectangle is:6.600000

...Program finished with exit code 0
Press ENTER to exit console```

So what am I doing that is different to you?
Check you have compiled the app and are running the right EXE file.

Nithish Karthikeyan 22-Oct-21 15:41pm
Instead of using a comma to separate the inputs I used a space..

## Solution 2

The input is wrong, must be delimited with space. Better is to write clean code and seperate both inputs:
C++
```int main()
{
float length, breadth, area;
printf("enter length:");
scanf("%f",&length,);
printf("breadth of the rectangle:");
printf("the area of the rectangle is:%f",area);
return 0;
}```
it is clearer, easier and understandable and more fun to read ;-)

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

Top Experts
Last 24hrsThis month
 OriginalGriff 95 Richard MacCutchan 40 Graeme_Grant 30 merano99 20 Tony Hill 15
 OriginalGriff 65 Richard MacCutchan 30 merano99 20 Graeme_Grant 10 Mike Hankey 10

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