Thread: Function Not Acepted

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    11

    Function Not Acepted

    Can someone please help me to deal with this function, which is giving me a c2064 error? Here is the code:

    Code:
    /**************************** Compiler Directives ****************************/
    
    #include <cstdlib>
    #include <iostream>
    #include <iomanip>
    #include <ctime>
    #include <cmath>
    #include <string>
    
    using namespace std;
    
    /**************************** Global Data Declarations ***********************/
    
    
    /***************************** Function Prototypes ***************************/
    
    void AnswerKey(int&	PLAY,				//IN: PLAYER CHOICE TO CONTINUE GAME
    			   int& QUIT);				//IN: PLAYER CHOICE TO QUIT GAME
    
    void NewRandomizer(int& random_number);	//OUT: RANDOM GENERATED NUMBER
    
    void PlayMachine(int& random_number,	//IN/OUT: RANDOM GENERATED NUMBER
    				 int& number);			//IN: PLAYER ENTERED NUMBER
    
    void StartGame(int& random_number,		//IN: RANDOM GENERATED NUMBER
    			   int& number);			//IN: NUMBER ENTERED BY PLAYER
    
    void DisplayMessage(int& random_number,	//IN: RANDOM GENERATED NUMBER
    					int& number,
    					int& guess());		//IN: RANDOM GENERATED NUMBER
    
    void DisplayGuesses(int guessArray[], int numGuesses);
    
    /******************************************************************************
    * Pseudocode:
    *	Level 0
    *	-------
    *		
    *		Seed the random number generator
    *		Generate a random number
    *		Input a number
    *		Display hi/low message
    *		Display results
    *		
    *	Level 1
    *	-------
    *		Seed the random number generator
    *			srand(static_cast<unsigned int>(time(0)))
    *		Generate a random number
    *			 random_number = (rand() &#37; (100 - 1 + 1)) + 1
    ******************************************************************************/
    
    int main()
    {
    
    	//LOCAL CONSTANTS
    	const int SIZE = 10;	//ARRAY SIZE
    
    	//Local variables
    	int counter = 0;	//TO TRACK PLAYER TRIES
    	int number;			//NUMBER ENTERED BY PLAYER
    	int random_number;	//RANDOM GENERATED NUMBER
    	//int intMax = 10;	//MAXIMUM AMOUNT OF TRIES
    	int guess[SIZE];	//PLAYER GUESSES
    	
    	//int guess_numbers;
    
    	int PLAY = 1;	//ANSWER TO PLAY AGAIN
    	int QUIT =0;	//ANSWER TO QUIT GAME
    	int flag =1;
    
    	cout << "==============================================" << endl;
    	cout << endl;
    	cout << "<<<<< WELCOME TO THE MIND BUSTER GAME >>>>>" << endl;
    	cout << endl;
    	cout << "  >>>>>>===== By: **************** =====>" << endl;
    	cout << endl;
    	cout << "  * YOU WILL HAVE ONLY 10 TRIES TO WIN *" << endl;
    	cout << endl;
    	cout << "==============================================" << endl;
    
    	//CALL FUNCTION TO GENERATE A RANDOM NUMBER
    	StartGame(random_number, number);
    
    	while(PLAY == 1)
    	{
    
    		while (counter < SIZE && flag == 1)
    			{
    				cout << "Enter a number ---> ";
    				cin >> number;
    
    				guess[counter] = number;
    				counter ++;
    
    				//IF USER GUESSES THE RANDOM NUMBER
    				if (number == random_number) 
    				{
    					cout << "Congratulations, You Win. ";
    					cout << "It Took You " << counter << " Attempts to Win" << endl;
    					//cout << "your numbers were " << guess << endl;
    					flag = 0;
    
    					//CALL FUNCTION TO ASK TO PLAY OR QUIT GAME
    					//AnswerKey(PLAY, QUIT);				
    				}
    
    				//IF NUMBER ENTERED BY USER IS LESS THAN RANDOM NUMBER
    				else if (number < random_number)
    				{
    					cout << "Too Low; Try Again" << endl;
    				}
    						
    				//IF NUMBER ENTERED BY THE USER IS GREATER THAN THE RANDOM NUMBER
    				else if (number > random_number)
    				{
    					cout << "Too High, Try Again" << endl;
    				}
    				//counter ++;
    				cout << endl;
    
    			}//End While
    
    			//DISPLAY MESSAGE WHEN PAYER LOOSES
    			DisplayGuesses(guess, counter); //********************
    
    			//CALL DISPLAY MESSAGE FUNCTION
    			if ((counter >= SIZE) || (random_number != number))
    			{
    				DisplayMessage(random_number, guess(), counter);
    			
    			}//END IF
    
    			else
    			{	
    				//CALL ANSWER KEY FUNCTION
    				AnswerKey(PLAY, QUIT);
    			}
    
    		}//END WHILE
    	
    	
    	//INDICATES A SUSCCESSFUL TERMINATION OF PROGRAM
    return 0;
    
    }//End main
    
    //******************** Start StartGame Function Executables *******************/
    
    void StartGame(int& random_number,	//OUT: RANDOM GENERATED NUMBER
    			   int& number)			//IN/OUT: PLAYER ENTERED NUMBER
    {
    
    		//SEED THE RANDOM NUMBER WITH SYSTEM CLOCK
    		srand(static_cast<unsigned int>(time(0)));
    		
    		//GENERATING A RANDOM NUMBER FROM 1 - 100
    		random_number = (rand() % (100 - 1 + 1)) + 1;
    			
    }
    
    /********************* Begin AnswerKey Function Executables ******************/
    
    void AnswerKey(int& PLAY,	//IN: PLAY THE GAME AGAIN
    			   int& QUIT)	//IN: QUIT THE GAME
    
    {
    	//Local variables
    	int answer;			//CHOICE FROM PLAYER
    
    		cout << "Want to Play Again?; Enter 1 for Yes or 0 to Quit " << endl;
    		cin >> answer;
    
    		//CLEARING THE SCREEN
    		system("cls");
    
    			//if (answer == PLAY)
    			//{
    				//main();
    			//}
    
    			//else if (answer == QUIT) 
    
    				//cout <<endl;
    				//cout << " *** THANKS FOR PLAYING *** " << endl;
    				//cout << endl;
    }
    
    /******************* Begin DisplayMessage Function Executables *****************/
    
    void DisplayMessage(int& random_number,	//IN/OUT: RANDOM GENERATED NUMBER
    					int& number,
    					int& guess)		//IN: NUMBER ENTERED BY PLAYER
    {
    
    	//CLEARING THE SCREEN
    	system("cls");
    
    	//DISPLAYING FAILURE TO WIN MESSAGE
    	cout << " <<<<< YOU LOST! >>>>> " << endl;
    	cout << endl;
    	cout << endl;
    	cout << "The Correct Answer Was: " << random_number << endl;
    	cout << endl;
    
    	//CALLING FUNTION TO PLAY OR QUIT GAME	
    	//AnswerKey(PLAY, QUIT);
    }
    
    /************ Begin displayGuesses Function Executables **********************/
    
    void DisplayGuesses(int guessArray[], int numGuesses)
    {
    	for (int i = 0; i < numGuesses; i++)
    	{
    		cout << "Your Guesses Were: " << guessArray[i] << endl;
    	}
    }
    
    //C/C++ test results are as follows:
    
    ***********  THE LINES BELOW WERE THE RESULT OF A COMPILER ****************
    
        /**************************** Compiler Directives ****************************/
    //  ^
    
    // line 149: error: expression must have (pointer-to-) function type
    //  		DisplayMessage(random_number, guess(), counter);
    // 				                              ^
    
    // line 149: error: argument of type "int" is incompatible with
    //          parameter of type "int &(*)()"
    //  				DisplayMessage(random_number, guess(), counter);
    //  			                                       ^
    Thanks in advance.
    Last edited by telepatico; 12-15-2007 at 01:57 PM.

  2. #2
    Captain - Lover of the C
    Join Date
    May 2005
    Posts
    341
    DisplayMessage doesn't even use the second 2 parameters: guess and number. Why not change it to just take 1 parameter and then pass it 1 parameter?

    [edit]Also, if you want to repeat the game, you have to reset all you variables in the while loop[/edit]
    Last edited by Brad0407; 12-15-2007 at 02:14 PM.
    Don't quote me on that... ...seriously

  3. #3
    Registered User
    Join Date
    Dec 2007
    Posts
    11
    I changed to just one parameter, but it seems not to behave properly. I will try a little harder and see.

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Code:
    DisplayMessage(random_number, guess(), counter);
    Guess is not a function; it's an array.

    ...And what's this?
    Code:
    void DisplayMessage(int& random_number,	//IN: RANDOM GENERATED NUMBER
    					int& number,
    					int& guess());		//IN: RANDOM GENERATED NUMBER
    I don't know how the compiler interprets that - but in any case, it's wrong.

    Code:
    void StartGame(int& random_number,	//OUT: RANDOM GENERATED NUMBER
    			   int& number)			//IN/OUT: PLAYER ENTERED NUMBER
    StartGame never uses number, so it's unreferenced. You can remove it.

    function AnswerKey: move to main and handle that there, in case the user wants to retry.

    Code:
    void DisplayMessage(int& random_number,	//IN/OUT: RANDOM GENERATED NUMBER
    					int& number,
    					int& guess)		//IN: NUMBER ENTERED BY PLAYER
    number and guess are unreferenced - never used. You can remove them.

    Also recommend std::vector for your arrays.
    Last edited by Elysia; 12-15-2007 at 02:36 PM.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    Captain - Lover of the C
    Join Date
    May 2005
    Posts
    341
    Quote Originally Posted by telepatico View Post
    I changed to just one parameter, but it seems not to behave properly. I will try a little harder and see.
    What's it doing and what do you want it to do?
    Don't quote me on that... ...seriously

  6. #6
    Registered User
    Join Date
    Dec 2007
    Posts
    11
    On this game, the user has only 10 times to guess the random generated number. If user fails to guess within the max allowed time, a display message will say so. If user wins, then another displayed message will also tell. I used functions so I don't get too confused.

    The thing is, that after loosing, the programs is like running in a loop, or something. While the displayed results never dssapear from screen until I close the program, it flashes very fast.

    So that is out of my knowledge to tell you the truth. I can run the game and win or loose, and the results are fine, except the flashing screen and I guess quit the game after winning or loosing, not sure, but one of them is not working properly.

    I tried to fix the C2064 error first, the move the the next problem. That is why just mentioned one.

  7. #7
    Registered User
    Join Date
    Dec 2007
    Posts
    11
    Elysia;

    I am making changes as you recommended too, and see the difference. Thanks.

  8. #8
    Captain - Lover of the C
    Join Date
    May 2005
    Posts
    341
    I already gave you the solution to that problem:
    You need to RESET ALL YOUR VARIABLES inside the while loop(at the start of it, of course)
    Don't quote me on that... ...seriously

  9. #9
    Registered User
    Join Date
    Dec 2007
    Posts
    11

    It wont quit.

    Well guys;

    I made the changes (attached file). Now wont quit. but is getting a lot better.
    I will try to code so more. If any reply to this, I will go back as per this attached file and make changes from there then.
    Thanks.

  10. #10
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    No warnings. Congrats.
    Now, as for your "want to play again?" - you already did do a big while loop for when PLAY==1. So if the user does not want to play again, you can simple set it to 0, so the loop aborts.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  11. #11
    Registered User
    Join Date
    Dec 2007
    Posts
    11
    See; because my concentration in functions, what I did is to messed it up a little.
    Now, with the help of both of you, I am looking a it a little different.
    I will, do as you just mention Elysia, and keep going from there.
    I do appreciate how soon you guys helped me out.
    If everything goes ok, then I will post if necessary, to show the whole thing working.
    Thanks.

  12. #12
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    No warnings. Congrats.
    Well, just one (with g++), but it's a warning of no real consequence.
    Code:
    /tmp/game_file.cpp:222:22: warning: no newline at end of file
    Code:
    random_number = (rand() &#37; (100 - 1 + 1)) + 1;
    That's a bit overly complicated . . .

    By convention, all-uppercase identifier names are used for constants, not ordinary variables.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  13. #13
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by dwks View Post
    Well, just one (with g++), but it's a warning of no real consequence.
    Code:
    /tmp/game_file.cpp:222:22: warning: no newline at end of file
    Well, none with Visual Studio (level 4).
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  14. #14
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Well, that just goes to show that g++'s warnings are better.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  15. #15
    Registered User
    Join Date
    Dec 2007
    Posts
    11
    I wish I could get my netbeans 6 to work well when compiling with g++, but even when the system variables are set to cygwin/bin, and selected on the options in netbeans, still does not work. I am using visual studio 2005.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  3. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  4. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  5. const at the end of a sub routine?
    By Kleid-0 in forum C++ Programming
    Replies: 14
    Last Post: 10-23-2005, 06:44 PM