I normally program in PHP, but I'm starting to learn C++ as well. Most of this is making sense, but I am getting a parse error when compiling that doesn't make sense to me. My goal is to create a simple program that:
1. displays a menu, and ask for a choice
2. displays text based on the answer, and then goes back to #1.
I compared my code against the tuts I'm reading, and everything looks fine (though it obviously isn't).
Here is the compiler log:
Compiler: Default compiler
Executing g++.exe...
g++.exe "C:\[c++]\pig.cpp" -o "C:\[c++]\pig.exe" -g3 -I"C:\Dev-Cpp\include\c++" -I"C:\Dev-Cpp\include\c++\mingw32" -I"C:\Dev-Cpp\include\c++\backward" -I"C:\Dev-Cpp\include" -L"C:\Dev-Cpp\lib"
C:/[c++]/pig.cpp: In function `int main()':
C:/[c++]/pig.cpp:9: parse error before `{' token
C:/[c++]/pig.cpp:17: `display_answer' undeclared (first use this function)
C:/[c++]/pig.cpp:17: (Each undeclared identifier is reported only once for each
function it appears in.)
C:/[c++]/pig.cpp: In function `int display_answer(int)':
C:/[c++]/pig.cpp:20: `int display_answer(int)' used prior to declaration
C:/[c++]/pig.cpp:25: `display_menu' undeclared (first use this function)
C:/[c++]/pig.cpp: At global scope:
C:/[c++]/pig.cpp:37: ISO C++ forbids declaration of `display_menu' with no type
C:/[c++]/pig.cpp:37: `int display_menu()' used prior to declaration
C:/[c++]/pig.cpp:38: parse error before `return'
Execution terminated
Here is the code:
I figured start at the top, which is the parse error forCode:#include <iostream> using namespace std; int display_answer(int choice); int main() { cout << "Let's just get this damn thing to compile before calling the function.\n"; int display_menu() { cout << "What do you want to know?\n"; cout << "(choose a number)\n\n"; cout << "\t[1] Boxers or briefs?\n"; cout << "\t[2] How pretty are you?\n"; cout << "\t[3] Can I touch you?\n"; int choice; cin>>choice; display_answer(choice); } int display_answer(int choice) { switch(choice) { case 1: cout << "Boxer-breifs.\n"; display_menu(); break; case 2: cout << "7.2\n"; display_menu(); break; case 3: cout << "No.\n"; display_menu(); break; } } display_menu(); return 0; }
int display_menu()
{
Can someone please enlighten me? TIA



LinkBack URL
About LinkBacks


