Menu

String shows in output but variable does not

2007-08-07
2012-09-26
  • Nobody/Anonymous

    Here is my code.

    include <stdio.h>

    include <math.h>

    int main(void)
    {
    double x1=1, y1=5, x2=4, y2=7, side_1, side_2, distance;

          side_1 = x2-x1;
          side_2 = y2-y1;
          distance = sqrt((side_1*side_1)+(side_2*side_2));
    
          printf(&quot;The distance between the two points is \n&quot;, distance);
          getchar();
          return(0);
    

    }

    I am using version 4, on Windows XP. When the output shows it gives "The distance between the two points is " w/o the distance variable.
    I haven't programmed with Dev-C++ before, but figured it wasn't different from the others. So I was just trying a easy sample program and couldn't get the results.

    Sorry if I missed a post with this already or if I need to give more info let me know (didn't include log file since it was a short program)!

     
    • Steve

      Steve - 2007-08-08

      Yes, I read through it and thats what got me thinking about where it was saving to, didn't realize it was saving to my docs thought it was saving to a Dev folder. I didn't realize that spacing gave it such a fit either X{ Next time I'll read through the "Read this first" more extensively.

      On the other note, I tried downloading and using the newest version but it wasn't wanting to install correctly. I think I might try that again now that I have some more time. Thanks for the help Clifford.

       
      • Wayne Keen

        Wayne Keen - 2007-08-08

        To install correctly, you must uninstall the previous version completely. For most versions,
        simply running the uninstall and deleting the Dev directory is NOT sufficient.

        There are directions for doing that in the "Please Read" thread.

        Wayne

         
    • Wayne Keen

      Wayne Keen - 2007-08-07

      The problem is that there is an error in your code, you left out the format specifier for your float. Take a look at this line:

      printf("The distance between the two points is %f \n", distance);

      When you get through slapping yourself on the head, try to work from the assumption
      that something is wrong with your code rather than something is wrong with the
      tool. 99% of the time, that will be the case. At least, it is for ME. ;)

      Wayne

       
      • Wayne Keen

        Wayne Keen - 2007-08-07

        Note the line I posted is the fixed version, not your version.

        :)

        Wayne

         
    • Steve

      Steve - 2007-08-07

      Thanks, but I had 5.2f before and just left it out. I found that it was trying to link to my "my docs" and that was causing the issue. Stupid default saving error on my part. Thanks though Wayne.

      Steve

       
      • Nobody/Anonymous

        A) It is completely idiotic and a waste of our time to post "any" information that doesn't match your scenario.

        B) Your rationale doesn't ring of truth.

        Soma

         
        • Nobody/Anonymous

          Un-fucking-beleiveable

          (1) Screw up
          (2) Blame Dev
          (3) Have your mistake found
          (4) Claim that the code you posted wasn't really the code you were using.
          (5) Claim that a linker error led to a run-time error, and figure no one
          will know the difference.

          Steve. you are a liar. I know it, you know it.

          anon2

           
        • Anonymous

          Anonymous - 2007-08-07

          ... and what does 'trying to link to my "my docs"' mean?

           
          • Wayne Keen

            Wayne Keen - 2007-08-07

            Anyone want to bet if Steve ever reappears on this thread?

            Soma, my email is finally unhosed. Drop me a note please, I have a question.

            Wayne

             
    • Steve

      Steve - 2007-08-07

      Ouch. All I know is I changed the spot where the file was being saved to and that made it work. I had %.2f earlier, sorry not 5.2f (mistype), but I forgot to put it back in. So yes this is where part of my error was coming from. I had also put in the %f that Wayne mentioned but I was still not getting the distance. But I was still getting this linking error after I checked the linker tab. I have never used Dev-c++ before and had no idea, but I decided to change where the files were being saved to the dev-c++ folder and this made it work. I am a noob at Dev and I haven't messed with C since high school. Sorry. I wasn't trying to blame anything. I knew it was something that just wasn't right on my part.

       
      • Anonymous

        Anonymous - 2007-08-08

        There are two kinds of path you should not put your files in because it causes problems:

        1) In or below the Dev-C++ installation folder (weird bug)
        2) Any path containing spaces - including the Desktop or My Documents when at default locations.

        The latter of these is clearly mentioned in the "PLEASE READ BEFORE POSTING A QUESTION", which no doubt by nature of its title you've read ;-), and almost every other thread in the forum besides (because no one actually seems to read the conspicuously titled thread!).

        That thread also mentions posting the compile log - had your project used an ill-advised path you would have been informed immediately and had your problem resolved.

        Clifford

         
      • Nobody/Anonymous

        Code with a linker error WILL NOT run!

        anon2

         
    • Anonymous

      Anonymous - 2007-08-08

      Oh, and BTW make sure you are using version 4.9.9.2 rather than version 4

      Clifford

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.