function problem

Discussion in 'Programmer's Corner' started by TAKYMOUNIR, Oct 14, 2012.

  1. TAKYMOUNIR

    Thread Starter Active Member

    Jun 23, 2008
    351
    1
    k=fu(x); i have problem with this function in the code the value is zero all the time can you please see what is wrong

    Code ( (Unknown Language)):
    1.  
    2. #include<stdio.h>
    3. #include<math.h>
    4. double area(double x,double y);
    5. int fu(int l);
    6. int main(){
    7. double x ,y ,z,k;
    8. printf("enter two number");
    9. scanf("%lg%lg",&x,&y);
    10. z=area(x,y);
    11. k=fu(x);
    12. printf("area is z =%lg and k is%d",z,k);
    13. return 0;
    14.  
    15. }
    16. double area(double x,double y){
    17. double z;
    18. z=x*y;
    19. return z;}
    20. int fu(int l){
    21. return l+l;}
    22.  
     
    • fu.txt
      File size:
      347 bytes
      Views:
      22
    Last edited by a moderator: Oct 15, 2012
  2. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,887
    1,019
    Why are you still posting your code in attachments and not posting them in line like kubeek showed you in this thread?

    http://forum.allaboutcircuits.com/showthread.php?t=75644


    What happens when you debug the code? What are the values of x,y and z, before and after the function is called?
     
    TAKYMOUNIR likes this.
  3. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    What software are you using?

    I strongly suggest to use the debugger in single-step mode.

    Then OP could write "I used the debugger, the variable a obtained the value blabla, but then in the line containing the code foobar, it is changing to 12345, and I don't properly understand why.

    This is called "isolating the problem".

    It is still a small piece of code. But confronting readers of a forum post with code; without explanation how it has been worked at, what happened, what exactly is unclear, at times can be rude.

    OP write the value is zero at all times. Great. Some explanation.
    In which line do you expect it to change to what value, and why? And what happened instead?
     
    TAKYMOUNIR likes this.
  4. TAKYMOUNIR

    Thread Starter Active Member

    Jun 23, 2008
    351
    1
    how can i post like this
     
  5. John P

    AAC Fanatic!

    Oct 14, 2008
    1,634
    224
    What did you find when you looked at the note "Sticky: Use of CODE tags" at the top of this section? And the use of capital letters and punctuation would make your messages easier to read.

    One thing I saw in your code was an attempt to print a C double quantity with a %d format.
     
Loading...