Thread: Errors that make no sense...

  1. #16
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    You last post did not have the proper include:

    #include <iostream>

    so be sure to always check that the proper includes are at the top of the file.

  2. #17
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398

    Some general advice, applescruff...

    Read this when you're no longer in frustration-mode... or is it panic-mode? Maybe after you get your program working.

    Develop your code a few lines at a time.

    Someday I'm going to write an essay on this topic. It seems like a lot of instructors don't really teach how to approach a programming problem. This result in lots of frustrated beginners & students. Nobody... not even experienced programmers write the whole program before trying it out!

    1- Start-out with a 'Hello World" type program. You can substitute "Hello World" with some better descriptiion of the program.

    2- Add one or two lines of code at a time. Compile, test-run, and debug before adding more lines.

    3- Add some extra cout statements so you can "see" what the program is doing, and confirm that it's working so-far. (You can take them out, or coment them out later.)

    4- When you create a function, make an empty (do-nothing) function first. Make the function prototype, the empty function definition, and the function call. Then, test-compile. If your function needs to return a value, just make it return a constant (i.e. return 10; ). It's also helpful to put a cout statement in your do-nothing function, like: cout << "In GetDistance() function \n"; .

    Now, this isn't as easy as it sounds, because you can't just write line one, then line two, then line three, of your code. (It won't compile if you do that.) The trick (the fun part, actually) is figuring-out which part of the code makes sense to develop next.

    Compilers can easily get confused when there's an error (or two). Sometimes they will point to the wrong line. Sometimes one error will cause the compiler to report several errors. Link errors are even trickier to track-down.

    So, it really helps to test-run and test-compile after every one or two lines. As you gain experience, you can write whole functions before testing. But, as you gain experience your programs generally will get longer and more complex, so you still won't be writing the whole program before testing & debugging.

    I once had a misplaced bracket (after a cut-and-past), and the comipler reported over one hundred errors! ... from one tiny little misplaced bracket!
    Last edited by DougDbug; 03-02-2005 at 03:43 PM.

  3. #18
    High school loser
    Join Date
    Dec 2004
    Posts
    27
    Dear lord, over 100 errors from a missing bracket?
    You think debugging the code is the fun part?
    Whoa.
    Last edited by applescruff; 03-04-2005 at 04:16 PM.
    "Confused by previous errors. Bailing out." --Bloodshed DevC++ compiler

  4. #19
    Registered User
    Join Date
    Feb 2005
    Location
    oslo
    Posts
    26
    I was bored and saw this thread, here is how I would have done it:

    Code:
    #include <iostream>
    #include <stdlib.h>
    #include <math.h>
    
    using namespace std;
        
    double GetDistance(double X1, double Y1, double X2, double Y2) {
            double d = sqrt(pow((Y2-Y1), 2.0) + pow((X2-X1), 2.0));
    	return d;
    }
    
    int main()
    {
      double X1, Y1, X2, Y2, result;
    
      cout << "Enter the coordinates of two points (X1,X2),(Y1,Y2)" << endl;
      cin >> X1 >> X2 >> Y1 >> Y2;
    
      result = GetDistance(X1, Y1, X2, Y2);
    
    
      cout << "The distance between (" << X1 << ", " << X2 <<
              ") and (" << Y1 << ", " << Y2 << ") is " << result << "." << endl;
    
      system ("PAUSE");
      return 0;
    }
    no need for extra functions when you dont have to!
    Dag

  5. #20
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    I was bored and saw this thread, here is how I would have done it:
    Please familiarize yourself with the cboard homework policy:

    http://cboard.cprogramming.com/annou...ouncementid=39

  6. #21
    Registered User
    Join Date
    Feb 2005
    Location
    oslo
    Posts
    26
    Okay, I thought that was just if the person were asking others to do his homework.... Not if someone just wants to write the code. I think that is a good way to learn(for me or the person who try to write it)-- by sharing code, getting comments back.
    Sorry if I did wrong.

  7. #22
    High school loser
    Join Date
    Dec 2004
    Posts
    27
    Thanks again to everyone who helped us out. One less major source of stress to deal with.
    "Confused by previous errors. Bailing out." --Bloodshed DevC++ compiler

  8. #23
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    Okay, I thought that was just if the person were asking others to do his homework.... Not if someone just wants to write the code.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Ten Errors
    By AverageSoftware in forum Contests Board
    Replies: 0
    Last Post: 07-20-2007, 10:50 AM
  2. how to make a windows application
    By crvenkapa in forum C++ Programming
    Replies: 3
    Last Post: 03-26-2007, 09:59 AM
  3. What to make?
    By Caldus in forum C++ Programming
    Replies: 4
    Last Post: 04-06-2005, 01:12 PM
  4. Errors in code
    By itzme in forum C++ Programming
    Replies: 12
    Last Post: 01-07-2005, 05:11 PM
  5. unknown errors (to me at least)
    By bcraig in forum C++ Programming
    Replies: 4
    Last Post: 11-18-2004, 10:19 PM