| | |
Function call problem
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
Hi guys, im trying to call a function with in another and for some reason i am getting
In function `int bDisplay()':
`move' undeclared (first use this function)
(Each undeclared identifier is reported only once for each function it appears in.)
In function `int move()':
`int move()' used prior to declaration
but the problem is that i have that function declared =(. What going on? Im making a memory tic tac toe game with AI and im fairly new into coding. So please don't flame my syntax =)
Also if it would be more clear to you guys if i posted everything i have right now please ask. Its not that long right now so it wouldnt take up that much space.
In function `int bDisplay()':
`move' undeclared (first use this function)
(Each undeclared identifier is reported only once for each function it appears in.)
In function `int move()':
`int move()' used prior to declaration
but the problem is that i have that function declared =(. What going on? Im making a memory tic tac toe game with AI and im fairly new into coding. So please don't flame my syntax =)
Also if it would be more clear to you guys if i posted everything i have right now please ask. Its not that long right now so it wouldnt take up that much space.
C++ Syntax (Toggle Plain Text)
int bDisplay() { cout<<"\n\n\n\n\n"; cout<<"\t\t\t\t"<<sOne<<" | "<<sTwo<<" | "<<sThree<<endl; cout<<"\t\t\t\t----------"<<endl; cout<<"\t\t\t\t"<<sFour<<" | "<<sFive<<" | "<<sSix<<endl; cout<<"\t\t\t\t----------"<<endl; cout<<"\t\t\t\t"<<sSeven<<" | "<<sEight<<" | "<<sNine<<endl; Sleep(2000); system("cls"); move(); } int winCond() { if (sOne == 'x' && sTwo == 'x' && sThree == 'x'){win();} if (sOne == 'x' && sFour == 'x' && sSeven == 'x'){win();} if (sOne == 'x' && sFive == 'x' && sNine == 'x'){win();} if (sTwo == 'x' && sFive == 'x' && sEight == 'x'){win();} if (sThree == 'x' && sFive == 'x' && sSeven == 'x'){win();} if (sThree == 'x' && sSix == 'x' && sNine == 'x'){win();} if (sFour == 'x' && sFive == 'x' && sSix == 'x'){win();} if (sSeven == 'x' && sEight == 'x' && sNine == 'x'){win();} } int move() { bool repeat; char choice; winCond(); do { repeat = false; cout<<"Please enter a selection 1-9:"; cin>>choice; switch (choice) { case 1: etc....
•
•
Join Date: Nov 2007
Posts: 390
Reputation:
Solved Threads: 39
Use a 2d array to represent the tic tac toe grid, not a seperate variable for each place >.< . And also...post the whole code. I don't understand why your calling wincond() at the start of main. It does literally nothing there. Also, never forget to initialize variables! Also, you are inputting a choice of type char, and are checking it against integers. While char and ints are very similar, the compiler does an ascii conversion for you in cases like this. If you want to check a char against an int, use single quotes '1' around it. If you don't, it will check against the ascii values of the char, whcih for 1 is 49 decimal, or 31 in hex. Ascii Table
You do have function prototypes, and the prototype for move( ) agrees with your implementation?
Seeing your full program would help.
Seeing your full program would help.
Everyone's gotta believe in something. I believe I'll have another drink.
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <windows.h> using namespace std; int sOne = 1; int sTwo = 2; int sThree = 3; int sFour = 4; int sFive = 5; int sSix = 6; int sSeven = 7; int sEight = 8; int sNine = 9; int win() { cout<<"gratz, you win the game!"; return (0); } int bDisplay() { cout<<"\n\n\n\n\n"; cout<<"\t\t\t\t"<<sOne<<" | "<<sTwo<<" | "<<sThree<<endl; cout<<"\t\t\t\t----------"<<endl; cout<<"\t\t\t\t"<<sFour<<" | "<<sFive<<" | "<<sSix<<endl; cout<<"\t\t\t\t----------"<<endl; cout<<"\t\t\t\t"<<sSeven<<" | "<<sEight<<" | "<<sNine<<endl; Sleep(2000); system("cls"); move(); } int winCond() { if (sOne == 'x' && sTwo == 'x' && sThree == 'x'){win();} if (sOne == 'x' && sFour == 'x' && sSeven == 'x'){win();} if (sOne == 'x' && sFive == 'x' && sNine == 'x'){win();} if (sTwo == 'x' && sFive == 'x' && sEight == 'x'){win();} if (sThree == 'x' && sFive == 'x' && sSeven == 'x'){win();} if (sThree == 'x' && sSix == 'x' && sNine == 'x'){win();} if (sFour == 'x' && sFive == 'x' && sSix == 'x'){win();} if (sSeven == 'x' && sEight == 'x' && sNine == 'x'){win();} } int move() { bool repeat; char choice; winCond(); do { repeat = false; cout<<"Please enter a selection 1-9:"; cin>>choice; switch (choice) { case 1: sOne = 'x'; break; case 2: sTwo = 'x'; break; case 3: sThree = 'x'; break; case 4: sFour = 'x'; break; case 5: sFive = 'x'; break; case 6: sSix = 'x'; break; case 7: sSeven = 'x'; break; case 8: sEight = 'x'; break; case 9: sNine = 'x'; break; default: cout<<"Sorry, bad input, please choose again."; repeat = true; } } while (repeat); ai(); }
Theres the full code right now. I didn't use arrays because of the simplicity of assigning new values to the int variables. But ya, their is no main() right now because im building the components needed first, before I attach them all to eachother. Again, i have not been programming for long, only a couple weeks, so take it easy on me =( Thanks!
You will need a main before you can properly compile your program.
Because as of right now I have no idea of what your program is supposed to do. Also you need to have return statements for your functions since they are all declared
If you do not want to return anything remove the int and make it
Because as of right now I have no idea of what your program is supposed to do. Also you need to have return statements for your functions since they are all declared
int functionName If you do not want to return anything remove the int and make it
void functionName . And she said "Let there be light" and on the seveth day Windows booted.
And the crowds screamed in terror and cowered in fear for Microsoft had approached.
From the testament of 10011101
And the crowds screamed in terror and cowered in fear for Microsoft had approached.
From the testament of 10011101
As I guessed, no function prototypes. The compiler sees your call of the move( ) function, but has no idea what that is, not having gottne that far in the code yet. Got back to your textbook or here for an explanation of what you need to do.
As kenji points out, you have at present only a collection of functions and some global variables (ooohh, you should be slapped on the wrist for that, too), but no actual program. Until you write function main( ), nothing will actually run.
As kenji points out, you have at present only a collection of functions and some global variables (ooohh, you should be slapped on the wrist for that, too), but no actual program. Until you write function main( ), nothing will actually run.
Everyone's gotta believe in something. I believe I'll have another drink.
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
•
•
Join Date: Oct 2006
Posts: 38
Reputation:
Solved Threads: 0
•
•
•
•
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <windows.h> using namespace std; int sOne = 1; int sTwo = 2; int sThree = 3; int sFour = 4; int sFive = 5; int sSix = 6; int sSeven = 7; int sEight = 8; int sNine = 9; int win() { cout<<"gratz, you win the game!"; return (0); } int bDisplay() { cout<<"\n\n\n\n\n"; cout<<"\t\t\t\t"<<sOne<<" | "<<sTwo<<" | "<<sThree<<endl; cout<<"\t\t\t\t----------"<<endl; cout<<"\t\t\t\t"<<sFour<<" | "<<sFive<<" | "<<sSix<<endl; cout<<"\t\t\t\t----------"<<endl; cout<<"\t\t\t\t"<<sSeven<<" | "<<sEight<<" | "<<sNine<<endl; Sleep(2000); system("cls"); move(); } int winCond() { if (sOne == 'x' && sTwo == 'x' && sThree == 'x'){win();} if (sOne == 'x' && sFour == 'x' && sSeven == 'x'){win();} if (sOne == 'x' && sFive == 'x' && sNine == 'x'){win();} if (sTwo == 'x' && sFive == 'x' && sEight == 'x'){win();} if (sThree == 'x' && sFive == 'x' && sSeven == 'x'){win();} if (sThree == 'x' && sSix == 'x' && sNine == 'x'){win();} if (sFour == 'x' && sFive == 'x' && sSix == 'x'){win();} if (sSeven == 'x' && sEight == 'x' && sNine == 'x'){win();} } int move() { bool repeat; char choice; winCond(); do { repeat = false; cout<<"Please enter a selection 1-9:"; cin>>choice; switch (choice) { case 1: sOne = 'x'; break; case 2: sTwo = 'x'; break; case 3: sThree = 'x'; break; case 4: sFour = 'x'; break; case 5: sFive = 'x'; break; case 6: sSix = 'x'; break; case 7: sSeven = 'x'; break; case 8: sEight = 'x'; break; case 9: sNine = 'x'; break; default: cout<<"Sorry, bad input, please choose again."; repeat = true; } } while (repeat); ai(); }
Theres the full code right now. I didn't use arrays because of the simplicity of assigning new values to the int variables. But ya, their is no main() right now because im building the components needed first, before I attach them all to eachother. Again, i have not been programming for long, only a couple weeks, so take it easy on me =( Thanks!
Hi,
Please write the body of move function before bDisplay() function. Your mistake is that
You are calling the move() function before, but you are defining its body after your calling function. Write your code in parent child top to bottom hierarchy. ok It will now compile and run successfully.okay
--
Regards,
Asif
![]() |
Similar Threads
- python function call for a noob (Python)
- my max function in my array wont work (C++)
- no matching function call (C++)
- function calling problem (C)
- no matching function for call to 'strcmp(std::string&, std::string&)' (C++)
- Function call problem (HTML and CSS)
- C++ pointers problem (C++)
- AnsiString Template Data Return Problem Builder 6 (C++)
- Stack Queue Fstream (C++)
Other Threads in the C++ Forum
- Previous Thread: C++ Program have one error :)
- Next Thread: input map coordinates into map
| Thread Tools | Search this Thread |
api application array arrays based beginner binary c++ c/c++ calculator char char* class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib library linkedlist linker list loop looping loops map math matrix memory newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg simple sorting string strings studio temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






