Function call problem

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jul 2008
Posts: 111
Reputation: clutchkiller is an unknown quantity at this point 
Solved Threads: 1
clutchkiller's Avatar
clutchkiller clutchkiller is offline Offline
Junior Poster

Function call problem

 
0
  #1
Nov 6th, 2008
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.

  1. int bDisplay()
  2. {
  3. cout<<"\n\n\n\n\n";
  4. cout<<"\t\t\t\t"<<sOne<<" | "<<sTwo<<" | "<<sThree<<endl;
  5. cout<<"\t\t\t\t----------"<<endl;
  6. cout<<"\t\t\t\t"<<sFour<<" | "<<sFive<<" | "<<sSix<<endl;
  7. cout<<"\t\t\t\t----------"<<endl;
  8. cout<<"\t\t\t\t"<<sSeven<<" | "<<sEight<<" | "<<sNine<<endl;
  9. Sleep(2000);
  10. system("cls");
  11. move();
  12. }
  13.  
  14. int winCond()
  15. {
  16. if (sOne == 'x' && sTwo == 'x' && sThree == 'x'){win();}
  17. if (sOne == 'x' && sFour == 'x' && sSeven == 'x'){win();}
  18. if (sOne == 'x' && sFive == 'x' && sNine == 'x'){win();}
  19. if (sTwo == 'x' && sFive == 'x' && sEight == 'x'){win();}
  20. if (sThree == 'x' && sFive == 'x' && sSeven == 'x'){win();}
  21. if (sThree == 'x' && sSix == 'x' && sNine == 'x'){win();}
  22. if (sFour == 'x' && sFive == 'x' && sSix == 'x'){win();}
  23. if (sSeven == 'x' && sEight == 'x' && sNine == 'x'){win();}
  24. }
  25.  
  26.  
  27. int move()
  28. {
  29. bool repeat;
  30. char choice;
  31. winCond();
  32.  
  33. do {
  34.  
  35. repeat = false;
  36. cout<<"Please enter a selection 1-9:";
  37. cin>>choice;
  38.  
  39. switch (choice)
  40. {
  41. case 1:
  42. etc....
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 671
Reputation: Freaky_Chris is a jewel in the rough Freaky_Chris is a jewel in the rough Freaky_Chris is a jewel in the rough 
Solved Threads: 113
Freaky_Chris's Avatar
Freaky_Chris Freaky_Chris is offline Offline
Practically a Master Poster

Re: Function call problem

 
0
  #2
Nov 6th, 2008
without the function call aswell it is hard to see what the problem is.

Chris
Knowledge is power -- But experience is everything
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 390
Reputation: skatamatic will become famous soon enough skatamatic will become famous soon enough 
Solved Threads: 39
skatamatic skatamatic is offline Offline
Posting Whiz

Re: Function call problem

 
0
  #3
Nov 6th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 1,679
Reputation: vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold 
Solved Threads: 193
vmanes's Avatar
vmanes vmanes is offline Offline
Posting Virtuoso

Re: Function call problem

 
0
  #4
Nov 6th, 2008
You do have function prototypes, and the prototype for move( ) agrees with your implementation?

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.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 111
Reputation: clutchkiller is an unknown quantity at this point 
Solved Threads: 1
clutchkiller's Avatar
clutchkiller clutchkiller is offline Offline
Junior Poster

Re: Function call problem

 
0
  #5
Nov 6th, 2008
  1. #include <iostream>
  2. #include <windows.h>
  3.  
  4. using namespace std;
  5.  
  6. int sOne = 1;
  7. int sTwo = 2;
  8. int sThree = 3;
  9. int sFour = 4;
  10. int sFive = 5;
  11. int sSix = 6;
  12. int sSeven = 7;
  13. int sEight = 8;
  14. int sNine = 9;
  15.  
  16. int win()
  17. {
  18. cout<<"gratz, you win the game!";
  19. return (0);
  20. }
  21.  
  22. int bDisplay()
  23. {
  24. cout<<"\n\n\n\n\n";
  25. cout<<"\t\t\t\t"<<sOne<<" | "<<sTwo<<" | "<<sThree<<endl;
  26. cout<<"\t\t\t\t----------"<<endl;
  27. cout<<"\t\t\t\t"<<sFour<<" | "<<sFive<<" | "<<sSix<<endl;
  28. cout<<"\t\t\t\t----------"<<endl;
  29. cout<<"\t\t\t\t"<<sSeven<<" | "<<sEight<<" | "<<sNine<<endl;
  30. Sleep(2000);
  31. system("cls");
  32. move();
  33. }
  34.  
  35. int winCond()
  36. {
  37. if (sOne == 'x' && sTwo == 'x' && sThree == 'x'){win();}
  38. if (sOne == 'x' && sFour == 'x' && sSeven == 'x'){win();}
  39. if (sOne == 'x' && sFive == 'x' && sNine == 'x'){win();}
  40. if (sTwo == 'x' && sFive == 'x' && sEight == 'x'){win();}
  41. if (sThree == 'x' && sFive == 'x' && sSeven == 'x'){win();}
  42. if (sThree == 'x' && sSix == 'x' && sNine == 'x'){win();}
  43. if (sFour == 'x' && sFive == 'x' && sSix == 'x'){win();}
  44. if (sSeven == 'x' && sEight == 'x' && sNine == 'x'){win();}
  45. }
  46.  
  47.  
  48. int move()
  49. {
  50. bool repeat;
  51. char choice;
  52. winCond();
  53.  
  54. do {
  55.  
  56. repeat = false;
  57. cout<<"Please enter a selection 1-9:";
  58. cin>>choice;
  59.  
  60. switch (choice)
  61. {
  62. case 1:
  63.  
  64. sOne = 'x';
  65. break;
  66.  
  67. case 2:
  68.  
  69. sTwo = 'x';
  70. break;
  71.  
  72. case 3:
  73.  
  74. sThree = 'x';
  75. break;
  76.  
  77. case 4:
  78.  
  79. sFour = 'x';
  80. break;
  81.  
  82. case 5:
  83.  
  84. sFive = 'x';
  85. break;
  86.  
  87. case 6:
  88.  
  89. sSix = 'x';
  90. break;
  91.  
  92. case 7:
  93.  
  94. sSeven = 'x';
  95. break;
  96.  
  97. case 8:
  98.  
  99. sEight = 'x';
  100. break;
  101.  
  102. case 9:
  103.  
  104. sNine = 'x';
  105. break;
  106.  
  107. default:
  108.  
  109. cout<<"Sorry, bad input, please choose again.";
  110. repeat = true;
  111. }
  112. }
  113. while (repeat);
  114. ai();
  115. }

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!
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 128
Reputation: kenji is an unknown quantity at this point 
Solved Threads: 10
kenji's Avatar
kenji kenji is offline Offline
Junior Poster

Re: Function call problem

 
0
  #6
Nov 6th, 2008
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 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
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 1,679
Reputation: vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold 
Solved Threads: 193
vmanes's Avatar
vmanes vmanes is offline Offline
Posting Virtuoso

Re: Function call problem

 
0
  #7
Nov 6th, 2008
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.
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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 38
Reputation: asifjavaid is an unknown quantity at this point 
Solved Threads: 0
asifjavaid asifjavaid is offline Offline
Light Poster

Re: Function call problem

 
0
  #8
Nov 7th, 2008
Originally Posted by clutchkiller View Post
  1. #include <iostream>
  2. #include <windows.h>
  3.  
  4. using namespace std;
  5.  
  6. int sOne = 1;
  7. int sTwo = 2;
  8. int sThree = 3;
  9. int sFour = 4;
  10. int sFive = 5;
  11. int sSix = 6;
  12. int sSeven = 7;
  13. int sEight = 8;
  14. int sNine = 9;
  15.  
  16. int win()
  17. {
  18. cout<<"gratz, you win the game!";
  19. return (0);
  20. }
  21.  
  22. int bDisplay()
  23. {
  24. cout<<"\n\n\n\n\n";
  25. cout<<"\t\t\t\t"<<sOne<<" | "<<sTwo<<" | "<<sThree<<endl;
  26. cout<<"\t\t\t\t----------"<<endl;
  27. cout<<"\t\t\t\t"<<sFour<<" | "<<sFive<<" | "<<sSix<<endl;
  28. cout<<"\t\t\t\t----------"<<endl;
  29. cout<<"\t\t\t\t"<<sSeven<<" | "<<sEight<<" | "<<sNine<<endl;
  30. Sleep(2000);
  31. system("cls");
  32. move();
  33. }
  34.  
  35. int winCond()
  36. {
  37. if (sOne == 'x' && sTwo == 'x' && sThree == 'x'){win();}
  38. if (sOne == 'x' && sFour == 'x' && sSeven == 'x'){win();}
  39. if (sOne == 'x' && sFive == 'x' && sNine == 'x'){win();}
  40. if (sTwo == 'x' && sFive == 'x' && sEight == 'x'){win();}
  41. if (sThree == 'x' && sFive == 'x' && sSeven == 'x'){win();}
  42. if (sThree == 'x' && sSix == 'x' && sNine == 'x'){win();}
  43. if (sFour == 'x' && sFive == 'x' && sSix == 'x'){win();}
  44. if (sSeven == 'x' && sEight == 'x' && sNine == 'x'){win();}
  45. }
  46.  
  47.  
  48. int move()
  49. {
  50. bool repeat;
  51. char choice;
  52. winCond();
  53.  
  54. do {
  55.  
  56. repeat = false;
  57. cout<<"Please enter a selection 1-9:";
  58. cin>>choice;
  59.  
  60. switch (choice)
  61. {
  62. case 1:
  63.  
  64. sOne = 'x';
  65. break;
  66.  
  67. case 2:
  68.  
  69. sTwo = 'x';
  70. break;
  71.  
  72. case 3:
  73.  
  74. sThree = 'x';
  75. break;
  76.  
  77. case 4:
  78.  
  79. sFour = 'x';
  80. break;
  81.  
  82. case 5:
  83.  
  84. sFive = 'x';
  85. break;
  86.  
  87. case 6:
  88.  
  89. sSix = 'x';
  90. break;
  91.  
  92. case 7:
  93.  
  94. sSeven = 'x';
  95. break;
  96.  
  97. case 8:
  98.  
  99. sEight = 'x';
  100. break;
  101.  
  102. case 9:
  103.  
  104. sNine = 'x';
  105. break;
  106.  
  107. default:
  108.  
  109. cout<<"Sorry, bad input, please choose again.";
  110. repeat = true;
  111. }
  112. }
  113. while (repeat);
  114. ai();
  115. }

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
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 111
Reputation: clutchkiller is an unknown quantity at this point 
Solved Threads: 1
clutchkiller's Avatar
clutchkiller clutchkiller is offline Offline
Junior Poster

Re: Function call problem

 
0
  #9
Nov 7th, 2008
ok, that makes some sense because i know ive dinked around calling functions before. thanks. Im also going to do some research on the prototype stuff.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC