Appleseed
Appleseed SuperDork
10/28/10 9:14 p.m.

So I've been neglecting my C++ class as of late. I know there are programmers here so what the hell, right.

The task is to set up a program in with five regions in a city. Accident data in input and the program will tell the user which area has the lowest amount of accidents.

This is as far as I've gotten. The MS Visual Studio says that there are undeclared identifiers, crashN, crashS, crashS, crashW, and crashC. Any help is appreciated. Remember, I'm a beginner who's just learned about the call function. I can't use things we haven't learned yet, for obvious reasons. Thanks in advance.

Program:

include

include

using namespace std; const int NORTH = 0; const int SOUTH = 1; const int EAST = 2; const int WEST = 3; const int CENTRAL = 4; int getNumAccidents(int); //argument denotes area void findLowest(int,int,int,int,int);

int main() { crashN = getNumAccidents(NORTH); crashS = getNumAccidents(SOUTH); crashE = getNumAccidents(EAST); crashW = getNumAccidents(WEST); crashC = getNumAccidents(CENTRAL);

findLowest(crashN,crashS,crashE,crashW,crashC);

system("PAUSE"); return 0; } int getNumAccidents(actionRegion) { cout << "Number of accidents in the "; switch (actionRegion) { case NORTH : cout << "North area"; break; case SOUTH : cout << "South area"; break; case EAST : cout << "East area"; break; case WEST : cout << "West area"; break; case CENTRAL : cout << "Central area"; break; } cin >> crashes; while (crashes < 0) { cout << "Enter a positive number"; cin >> crashes; }

return crashes

}

EvanB
EvanB Dork
10/28/10 9:36 p.m.

I wish I could help but it's been a few years since I did any C++ and I don't really remember any of it.

BoxheadTim
BoxheadTim Dork
10/28/10 9:50 p.m.

If I deciphered the code correctly, it looks like your missing the type declarations for crashN/S/E - I guess they should be ints, like so:

int crashN = ...

oldopelguy
oldopelguy Dork
10/28/10 9:53 p.m.

Man this dates me, but if you were talking FORTRAN I could help you out, but that new fangled C never managed to stick with me.

Sigh

RoosterSauce
RoosterSauce New Reader
10/28/10 10:18 p.m.

I failed my college C++ class. Made my head hurt too much. Now I have a headache, again.

HiTempguy
HiTempguy HalfDork
10/29/10 12:14 a.m.
BoxheadTim wrote: If I deciphered the code correctly, it looks like your missing the type declarations for crashN/S/E - I guess they should be ints, like so: int crashN = ...

I would concur with this man's analysis. Having said that, I really hope that is NOT what your code actually looks like organization-wise. If it does, you definitely ain't no programmer and definitely are in engineering!

Giant Purple Snorklewacker
Giant Purple Snorklewacker SuperDork
10/29/10 6:41 a.m.

None of your crash* variables have been declared.

You will need a forward declare for getNumAccidents()

Your includes don't include anything... and so you will also get errors finding everything else like cout, etc.

scardeal
scardeal Reader
10/29/10 9:28 a.m.

Whoa. This takes me back.

I'm assuming that you didn't properly format it for posting here (2 spaces before single line break to line break properly)...

You didn't declare the Crash stuff properly (as above).

GameboyRMH
GameboyRMH SuperDork
10/29/10 1:21 p.m.

Whoa I hope the GRM forums mangled your code's formatting and it doesn't actually look like that

Appleseed
Appleseed SuperDork
10/29/10 9:39 p.m.

The formatting on the board fubar'ed that up good. I'll see if I can re-post it on Monday.

You'll need to log in to post.

Our Preferred Partners
zrXDjJMB4sRj2mjyjRUWPJ50flKIII8KdlZLUOJqpdJ2mPQ6A1AuPLd3LGd0vUJR