Hey guys, ive written this program for an assignment of mine, its a airline reservation system that allows a user to book seats within two classes, first and second. First class is seats 1-5, second class 6-10. Ive written a program that uses functions and im sure that ive missed something out because im getting this error:
(13) : error C3861: 'MainMenuDisplay': identifier not found
(18) : error C3861: 'FirstClass': identifier not found
p(22) : error C3861: 'SecondClass': identifier not found
You need to forward declare functions. On next line below global variables write
1 2 3
void FirstClass( int firstclass[]);
void SecondClass( int firstclass[]);
void MainMenuDisplay();
Additional notes:
Using global variables is very bad programing experience. You will defiantly lose some marks for that.
Your code formating sucks. Use http://en.wikipedia.org/wiki/Off-side_rule . Personally, I put two spaces, not 4 as you see in that example.
And there are many other things wrong with the program.
Ortonas is correct, you need to prototype your functions before they're called. Prototyping means putting basically the same thing as a variable declaration before you use a variable. The only thing that you have to tell the compiler is what the functions look like, so in Ortonas' example, you see the prototypes with no function definition. These must be placed before the function in which the function call is used.
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
void FirstClass(int firstclass[]); // Function prototype
int main(){
..
..
FirstClass(firstclass); // Function call
..
}
void FirstClass(int firstclass[]){
..
..
..
} // Function definition
As an aside, I program in the opposite direction. My int main() is always the last function that I put in the program; in fact, I try not to prototype if I can avoid it, instead putting all functions above where they are called, when possible. This is more of a personal technique, though, don't take it as c++ gospel.
Example:
1 2 3 4 5 6 7 8 9 10 11 12
void FirstClass(int firstclass[]){
..
..
..
} // Function definition
int main(){
..
..
FirstClass(firstclass); // Function call
..
}
If the type of variable doesn't match what you are trying to use it as, you will get errors. So if you want to have them be bool, you have to use them as a bool throughout the program. Likewise, if you want to use them as int, you should define them as int. I would recommend simply defining them to however your intent is to use them, rather than changing your use of them to match the definition, but either way the definition and the use have to match.