Win a copy of Terraform in Action this week in the Cloud forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Can someone evaluate what im missing in my code?

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello . I just started learning programming and I have encountered an exercise that asked me to wite a code that describes the distance between two points, this is what I could create so far:

Hello . I just started learning programming and I have encountered an exerise that asked me to wite a code that describes the distance between two points, this is what I could create so far:



Could you please help me find and correct my mistakes.
 
Rancher
Posts: 344
11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Denis

The mistakes are just 'typos'; missing semicolons on the ends of lines, missing commas, that sort of thing. The compiler will tell you were the mistakes are. There's nothing fundamentally 'wrong' with your code; I fixed the typos (identified by the compiler) and it worked.

Make sure you enable all warnings on the compiler command line - use -Wall if you are compiling with gcc.

John
 
Marshal
Posts: 74392
335
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

The logic of your code appears to be correct, but please always indent your code correctly, and put spaces between successive tokens; it is very difficult to read yuur code as it stands. You are mssing several commas and semicolons. Please correct those errors.

JM: I tried myself last night, and kept getting errors about, 𠇍istance.c:(.text+0x87): undefined reference to `sqrt'”. I could however get sqrt(2.0) to compile and run. ny idea what I have done wrong? Should I reinstall gcc?
 
John Matthews
Rancher
Posts: 344
11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:JM: I tried myself last night, and kept getting errors about, 𠇍istance.c:(.text+0x87): undefined reference to `sqrt'”. I could however get sqrt(2.0) to compile and run. ny idea what I have done wrong? Should I reinstall gcc?

I had to lookup how to link with the math library - "-lm" on the end of the command line (after the .c). But then that doesn't explain how it compiled with the 2.0 arg. Pass.
 
John Matthews
Rancher
Posts: 344
11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
...although I suspect sqrt(2.0) is just being optimised to a constant value. So yes, add -lm after the .c filename on the command line.
 
Campbell Ritchie
Marshal
Posts: 74392
335
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you; I shall try those options later.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic