Click here to Skip to main content
15,611,656 members
Please Sign up or sign in to vote.
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

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

//Driver function
         int main()
             float a,b,A;
             printf("enter length,breadth of the rectangle:");
             printf("the area of the rectangle is:%f",A);
             return 0;
Updated 22-Oct-21 22:41pm

The input is wrong, must be delimited with space. Better is to write clean code and seperate both inputs:
int main()
             float length, breadth, area;
             printf("enter length:");
             printf("breadth of the rectangle:");
             area = areaofrect(length,breadth);
             printf("the area of the rectangle is:%f",area);
             return 0;
it is clearer, easier and understandable and more fun to read ;-)
Share this answer
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.
Share this answer
Nithish Karthikeyan 22-Oct-21 15:41pm    
Instead of using a comma to separate the inputs I used a space..

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

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