PDA

Click to See Complete Forum and Search --> : I can't find the error! simple finding Area program


struntz
Dec 13th, 2000, 07:16 PM
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?


#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! :D

Sam Finch
Dec 13th, 2000, 07:51 PM
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.

struntz
Dec 13th, 2000, 08:17 PM
Hey thanks for helping me out!