Thread: Error: function does not take # parameters

  1. #1
    Amy amirahasanen1's Avatar
    Join Date
    Jul 2003
    Posts
    49

    Question Error: function does not take # parameters

    Hi there, I am starting to design a very simple game, I am not done with it, this is just a beginning of it, but I had a problem, I get the following error:
    Code:
    'rng': function does not take 1 parameters
    and even if I change number of parameters used I still get that error.
    Is there something wrong with my code?
    Thank you..

    -Amy


    Code:
    #include <iostream>
    #include <time.h>
    
    using namespace std;
    
    int rng();
    
    int main()
    {
    	char winlose;
    	rng(winlose);
    	cout<<winlose<<endl;
    
    	return 0;
    }
    
    int rng(char state)
    {
    	const int n = 6; // the number of faces of the dice
    	int x1, x2, sum; // the 2 number generated by the RNG (x1 & x2), and their sum
    	
    	srand ( (unsigned) time (NULL) ); //Initialize RNG
    	
    	x1 = rand( ) % n + 1;	// Generate a number from the sequence
    	cout<<x1<<" ";			// Print it
    			
    	x2 = rand( ) % n + 1;	// Generate another number from the sequence
    	cout<<x2<<endl;			// Print it
    
    	sum = x1 + x2; // summing the two randomly generated numbers
    	cout<<sum<<endl;
    
    	// if statment for checking if the sum of the 2 randomly generated numbers is 7 or 11
    	if((sum==7) || (sum==11))
    		state = 'w'; // w stands for win
    	else if((sum==2) || (sum==3) || (sum==12))
    		state = 'l'; // l stands for lose
    	else
    		state = 'n'; // n stands for neither nor
    	// end of if statment
    
    	return state;
    }
    It ain't illegal until you get caught..

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    Code:
    #include <iostream>
    #include <ctime>
    
    using namespace std;
    
    char rng();
    
    int main()
    {
    	char winlose;
    	winlose = rng();
    	cout<<winlose<<endl;
    
    	return 0;
    }
    
    char rng()
    {
    	const int n = 6; // the number of faces of the dice
    	int x1, x2, sum; // the 2 number generated by the RNG (x1 & x2), and their sum
    	
    	srand ( (unsigned) time (NULL) ); //Initialize RNG
    	
    	x1 = rand( ) % n + 1;	// Generate a number from the sequence
    	cout<<x1<<" ";			// Print it
    			
    	x2 = rand( ) % n + 1;	// Generate another number from the sequence
    	cout<<x2<<endl;			// Print it
    
    	sum = x1 + x2; // summing the two randomly generated numbers
    	cout<<sum<<endl;
    
    	// if statment for checking if the sum of the 2 randomly generated numbers is 7 or 11
    	if((sum==7) || (sum==11))
    		return 'w'; // w stands for win
    	else if((sum==2) || (sum==3) || (sum==12))
    		return 'l'; // l stands for lose
    	else
    		return 'n'; // n stands for neither nor
    	// end of if statment
    }
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    Amy amirahasanen1's Avatar
    Join Date
    Jul 2003
    Posts
    49
    Oh, thanks for clarifying, I always get confused when using functions between in's & out's of a function (i.e. parameters and returned value/s)..

    And by the way, why do you think I should use <ctime> instead of <time.h>?
    Thanks

    -Amy
    It ain't illegal until you get caught..

  4. #4
    Amy amirahasanen1's Avatar
    Join Date
    Jul 2003
    Posts
    49

    Question

    Now that I added a new function to the program, it still gets the same error:
    Code:
    'budgetcalculator': function does not take 3 parameters
    Why does the compiler give me this error?
    Thanks


    Code:
    // Including librarie(s) needed for running the program
    #include <iostream>
    #include <time.h>
    
    using namespace std;
    
    // declaring a prototype functions
    int rng();
    int budgetcalculator();
    
    // starting the main function
    int main()
    {
    	char winlose;
    	
    	winlose = rng();
    	
    
    	float budget = 10000;
    	float bet;
    	cin>>bet;
    	
    	budget = budgetcalculator(winlose, budget, bet);
    	cout<<budget;
    
    	return 0;
    }
    
    int rng()
    {
    	// declaring local variables
    	const int n = 6; // the number of faces of the dice
    	int x1, x2, sum; // the 2 number generated by the RNG (x1 & x2), and their sum
    	
    	srand ( (unsigned) time (NULL) ); //Initialize RNG
    	
    	x1 = rand( ) % n + 1;	// Generate a number from the sequence
    	cout<<x1<<" ";			// Print it
    			
    	x2 = rand( ) % n + 1;	// Generate another number from the sequence
    	cout<<x2<<endl;			// Print it
    
    	sum = x1 + x2; // summing the two randomly generated numbers
    	cout<<sum<<endl;
    
    	// if statment for checking if the sum of the 2 randomly generated numbers is 7 or 11
    	if((sum==7) || (sum==11))
    		return 'w';
    	else if((sum==2) || (sum==3) || (sum==12))
    		return 'l';
    	else
    		return 'n';
    	// end of if statment
    }
    //end of function
    
    int budgetcalculate(char state, float credit, float moneybet)
    {
    	if(moneybet<=credit)
    		if(state=='w')
    			credit += moneybet;
    		else if(state=='l')
    			credit -= moneybet;
    		return credit;
    }
    It ain't illegal until you get caught..

  5. #5
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    The reason you keep getting these errors is that the number of arguments specified in the function prototype does not agree with the number of arguments you are passing into the function and the number of arguments given in the function definition.

    Code:
    int budgetcalculator();  // Zero arguments defined
    
    ...
    
    budget = budgetcalculator(winlose, budget, bet); // Three arguments provided
    
    ...
    
    // Three arguments defined
    int budgetcalculate(char state, float credit, float moneybet)
    {
        if(moneybet<=credit)
            if(state=='w')
                credit += moneybet;
            else if(state=='l')
                credit -= moneybet;
        return credit;
    }
    The number of arguments in the prototype must agree with how many you pass into the function when you call it later or else the compiler will complain. Also, the return type should be a float. Change your code to this:
    Code:
    float budgetcalculate(char, float, float);
    
    ...
    
    float budgetcalculate(char state, float credit, float moneybet)
    {
        if(moneybet<=credit)
            if(state=='w')
                credit += moneybet;
            else if(state=='l')
                credit -= moneybet;
        return credit;
    }
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  6. #6
    Amy amirahasanen1's Avatar
    Join Date
    Jul 2003
    Posts
    49
    Yes, I thought this might be the solution, but when I tried it I got the following 2 errors:

    1.
    Code:
    unresolved external symbol "int__cdecl budgetcalculator(char,float,float)" (?budgetcalculator@@YAHDMM@Z)
    2.
    Code:
    1 unresolved externals
    Last edited by amirahasanen1; 03-08-2005 at 12:47 PM.
    It ain't illegal until you get caught..

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    > int rng();
    This means int rng(void); in C++ (this is different to what C would do in the same circumstance).
    Just make all your prototypes agree with the definitions - that's all there is to it.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  8. #8
    Amy amirahasanen1's Avatar
    Join Date
    Jul 2003
    Posts
    49
    I am sorry I don't want to be repeating my question, but after defining the arguments I still get those 2 errors..

    1.
    Code:
    unresolved external symbol "int__cdecl budgetcalculator(char,float,float)" (?budgetcalculator@@YAHDMM@Z)
    2.
    Code:
    1 unresolved externals
    It ain't illegal until you get caught..

  9. #9
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Code:
    int budgetcalculator(char, float, float);
    //...
    int budgetcalculate(char state, float credit, float moneybet)
    {
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  10. #10
    Amy amirahasanen1's Avatar
    Join Date
    Jul 2003
    Posts
    49
    Quote Originally Posted by Dave_Sinkula
    Code:
    int budgetcalculator(char, float, float);
    //...
    int budgetcalculate(char state, float credit, float moneybet)
    {

    Ohh!! Thank you
    I am sorry if I annoyed you ppl having such a simple mistyping error here in such a busy board..
    If I find any problems while continuing this simple game I will post here.. Thank you again for being helpful.

    -Amy
    It ain't illegal until you get caught..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 6
    Last Post: 07-21-2008, 06:04 AM
  2. function with variable number of parameters
    By mikahell in forum C++ Programming
    Replies: 3
    Last Post: 07-23-2006, 03:35 PM
  3. Additional parameters for operator delete
    By darksaidin in forum C++ Programming
    Replies: 0
    Last Post: 09-21-2003, 11:46 AM
  4. Passing parameters from VB to C++ through ActiveX DLL
    By torbjorn in forum Windows Programming
    Replies: 0
    Last Post: 12-10-2002, 03:13 AM
  5. command-line parameters.
    By Tombear in forum C Programming
    Replies: 2
    Last Post: 10-28-2001, 08:40 AM