Results 1 to 3 of 3

Thread: I can't find the error! simple finding Area program

  1. #1

    Thread Starter
    Registered User struntz's Avatar
    Join Date
    Aug 1999
    Location
    Brockway,Pa,USA
    Posts
    199

    Question

    Hello everyone!
    I am writing alittle program i just started learnign C++ and i can't stand the constant errors i keep getting and i think evertying is right, what did i do wrong here?


    Code:
    #include <iostream.h>
    
    int FindArea(int Lenght, int width){
         cout << "you've entered finding areafucntion" << endl;
         return (Length * width);
         }
    
    
    int main() {
        cout << "Enter Length and then Width." << endl;
        cin >> len;
        cin >> wid;
        int Area;
        Area = FindArea(len,wid);
        cout << Area << endl;
        return 0;
        }

    i get the errors:
    c:\my documents\c++programs\chapter2\findingarea.cpp: In function `int FindArea(int, int)':
    c:\my documents\c++programs\chapter2\findingarea.cpp:5: `Length' undeclared (first use this function)
    c:\my documents\c++programs\chapter2\findingarea.cpp:5: (Each undeclared identifier is reported only once
    c:\my documents\c++programs\chapter2\findingarea.cpp:5: for each function it appears in.)
    c:\my documents\c++programs\chapter2\findingarea.cpp:6: parse error before `}'
    c:\my documents\c++programs\chapter2\findingarea.cpp: In function `int main()':
    c:\my documents\c++programs\chapter2\findingarea.cpp:11: `len' undeclared (first use this function)
    c:\my documents\c++programs\chapter2\findingarea.cpp:12: `wid' undeclared (first use this function)


    Thanks for Listening!


  2. #2
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    I spotted 3,

    You had a Typo in the declartion of FindArea (you spelt Length wrong) and you forgot to declare len and wid in main. That probably accounts for all of them.

    If you're using VC++ then you can double click on an error and it'll point to it in the code, always fix errors one at a time, then rebuild, I've had 135 errors caused by a missing }.

    I can remember going through this myself when I was first starting, C++ gives you all the errors it can find in one go rather than pointing them out one at a time like VB, you get used to it, most of the time errors are caused by other errors so it only looks like a lot. believe it or not it is actually worth learning C++, even though it seems like a complete waste of time when you're sitting there with 200 errors in a piece of code that would take one line in VB.
    If it wasn't for this sentence I wouldn't have a signature at all.

  3. #3

    Thread Starter
    Registered User struntz's Avatar
    Join Date
    Aug 1999
    Location
    Brockway,Pa,USA
    Posts
    199

    Talking Thanks, that did it!

    Hey thanks for helping me out!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width