Thread: Please help with my code.

  1. #1
    Registered User
    Join Date
    Apr 2008

    Please help with my code.

    Ok, I have to write a function called distance that will calculate the distance between 2 points in an x-y coordinate system. Each point will be specified by 2 double values. Also, this function will not contain any input/output code (i.e. no printf or scanf function calls).

    Write a complete program that will test your function.

    How am I supposed to test my results, if I can't have no input/output code? Please help me.

    This is my code, but I haven't finished it yet, because I don't know what to do after that. Please help.

    #include <stdio.h>
    #include <math.h>
    using namespace std;
    double distance(double xOne, double yOne, double xTwo, double yTwo)
                      double xS, yS, result;
                      xS= xTwo - xOne;
                      xS= xS*xS;  // value of x squared under radical
                      yS = yTwo - yOne;
                      yS = yS*yS;  //value of y squared under radical
                      result = sqrt(xS + yS);
                      return result;

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    It says the FUNCTION cannot contain any input/output. I'm sure you can use it outside the function.

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Rishon LeZion, Israel
    using namespace std;
    This isn't C
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Extended ASCII Characters in an RTF Control
    By JustMax in forum C Programming
    Replies: 18
    Last Post: 04-03-2009, 08:20 PM
  2. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 07:34 AM
  3. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 04:17 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Replies: 0
    Last Post: 02-21-2002, 06:05 PM