Thread: Too few arguments in functions to call!

  1. #1
    Registered User
    Join Date
    Feb 2016
    Posts
    2

    Too few arguments in functions to call!

    Hello forum!
    Disclaimer: THIS IS HOMEWORK
    However, I do not want the answers to everything.
    I'm just very stuck on a single part.

    Referring to ->

    //function call to IsAWinner - returns to winOrLose variable (0 or 1)
    IsAWinner();
    //function call to CompareTheLetters - gives the user a message
    CompareTheLetters();

    For some reason, I'm getting "Error too few arguments in function call". Why am I getting this error?

    Thanks!


    Code:
    #define _CRT_SECURE_NO_WARNINGS#include <stdio.h>
    #define MAXGUESSES 4
    
    
    //function prototypes with a comment for each one describing what the function does.
    //Copy and paste from assignment
    
    
    //function prototypes with a comment for each one describing what the function does.
    //Copy and paste from assignment
    
    
    //this function provides instructions to the user on how to play the game
    void GuessItRules();
    //this function runs one game.
    //input: character from the file
    //The function returns a 0 if the user wins the game and a 1 if the user loses a game
    int PlayOneGame(char);
    
    
    //ALL FUNCTIONS BELOW are called from inside the PlayOneGame function described above
    
    
    //this function prompts the player to make a guess and returns that guess
    char GetTheLetter();
    //input: character from file and character guess from user
    //Returns 0 if the guess matches the solution and returns a 1 if they do not match
    int IsAWinner(char, char);
    //input: character from file and character guess from user
    //Prints a message if the guess comes alphabetically before, after, or equal to the letter
    void CompareTheLetters(char guess, char letter);
    
    
    
    
    
    
    int main()
    {
        //declare additional variables
        //declare FILE pointer
        FILE *inp;
        int numGames, i = 0;
        //letter from file
        char letter;
        //variable for the return of the PlayOneGame function
        //int didYouWin;
    
    
        //display instructions
        GuessItRules();
        //connect to the file HINT: use fopen
        inp = fopen("letterinput.txt", "r");
    
    
        //get number of games to play
        printf("How many games? (1 to 5): ");
        scanf("%d", &numGames);
    
    
        //this for loop will allow the player to play more than one game
        //without recompiling
        for (i = 0; i < numGames; i++)
        {
            //get a letter from file - use fscanf
            fscanf(inp, "%c", &letter);
            //print the letter back onto the screen, just to test
            //printf("\nThe letter is %c\n", letter);
    
    
            //Play one game (Call PlayOneGame function)
            //remember the function has an int return type
            printf("Let's play game %d\n", i + 1);
            //tell the player if they have won or lost (test the variable didYouWin)
    
    
        }
    
    
        //close file 
        return 0;
    }
    
    
    //Function definitions
    //keep the comments from the assignment
    
    
    //this function prompts the player to make a guess and returns that guess
    char GetTheLetter()
    {
        char guess;
        printf("Make a guess: \n");
        scanf("%c", &guess);
        return guess;
    }
    
    
    void CompareTheLetters(char guess, char letter)
    {
        if (guess == letter)
        {
            printf("You win!");
        }
        else
            if (guess < letter)
        {
            printf("The letter comes before your guess (%c)", guess);
        }
            else
                if (guess > letter)
                {
                    printf("The letter comes after your guess (%c)", guess);
                }
    
    
    }
    
    
    int IsAWinner(char guess, char letter)
    {
        if (guess == letter)
        {
            return 1;
        }
        else
            if (guess < letter)
            {
                return 0;
            }
            else
                if (guess > letter)
                {
                    return 0;
                }
    }
    
    
    int PlayOneGame(char solution)
    {
        int numGuesses = 0;
        //SHOULD BE INITIALZED TO 1
        int winOrLose = 1;
        // user guess
        char guess;
    
    
        
    
    
        //As long as the user  has not used up the maximum number
        //of guesses and has not guessed correctly 
        //the game will continue using this while loop
        while (numGuesses < MAXGUESSES && winOrLose == 1)
        {
    
    
            //function call to GetTheletter - returns to guess variable
            GetTheLetter();
            //function call to IsAWinner - returns to winOrLose variable (0 or 1)
            IsAWinner();
            //function call to CompareTheLetters - gives the user  a message
            CompareTheLetters();
            //update counter for number of guesses used
            numGuesses = numGuesses + 1;
    
    
        }
        
        return winOrLose;  //(0 or 1)
    
    
    }
    
    
    //add the other function definitions
    
    
    void GuessItRules()
    {
        printf("Welcome to the Letter Guessing Game\n");
        printf("\nFirst, you will enter the number of games you want to play (1 - 5 games)\n");
        printf("For each game you will have 4 chances to guess each letter\n");
        printf("Let's begin:\n");
    }

  2. #2
    Informer -Adrian's Avatar
    Join Date
    Jan 2013
    Posts
    819
    You declared IsAWinner and CompareTheLetters to each take two arguments. In your code however, you call them without supplying any arguments (lines 161 and 163). You cannot do that. There are a few other things that aren't quite right, but I assume this is a work in progress.

    You should have posted this in the C forum, as it doesn't appear to be C++. I'm sure a mod can move it, if necessary.

  3. #3
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Take a look at the signature of the function you want to call. It's here:
    Code:
    void CompareTheLetters(char guess, char letter)
    Now if you look at the code where you call this function inside PlayOneGame, then there is an obvious difference.
    Code:
        while (numGuesses < MAXGUESSES && winOrLose == 1)
        {
    
    
            //function call to GetTheletter - returns to guess variable
            GetTheLetter();
            //function call to IsAWinner - returns to winOrLose variable (0 or 1)
            IsAWinner();
            //function call to CompareTheLetters - gives the user  a message
            CompareTheLetters();
            //update counter for number of guesses used
            numGuesses = numGuesses + 1;
    
    
        }
    "Too few arguments." In general, you need to make sure the data flows properly through the program. For example, if GetTheLetter() returns something, and you don't store that in a variable, you lose that data. There are no variables to pass into the CompareTheLetter function.

  4. #4
    Registered User
    Join Date
    Feb 2016
    Posts
    2
    Swore I ticked reply.

    Alright, I believe I understand now. I need to resupply the arguments like so:

    IsAWinner(guess,letter);
    CompareTheLetters(guess, letter);

    Doing so fixed the error. But now I'm getting "letter" is undefined. I can define it by adding "char letter" under "char guess". However, I wonder why the professor included "char letter" under "int main()" instead of "int PlayOneGame()". I'll try a few things and get back to you with results!

    Code:
    IsAWinner(guess,letter);
    CompareTheLetters(guess, letter);
    Also, it is a work in progress and would like some additional input if willing. I like to do things on my own but sometimes get stuck.
    Thanks!

  5. #5
    Registered User
    Join Date
    Apr 2015
    Location
    Bangalore, Karnataka, India
    Posts
    34

    Where are you calling PlayOneGame() and where are you storing the guess variable?

    Looks like you have not written this code. You have copied from somewhere or somebody and haven't understood it correctly yet.

    Copying is not bad thing but you must understand the code what have you copied.

    Anyways, you have many problems in this code:
    it is too hard to explain you right away.

    As far as I understand the code reads a char from a file: which should be letter.
    You should call the PlayOneGame(char solution); at line# 71.
    The code should be like this:
    Code:
    PlayOneGame(letter);
    Then the GetTheLetter(); reads a value from the user.
    You should store the value that is returned from GetTheLetter(); at line# 159.

    Code at line#159 should be:
    Code:
    guess = GetTheLetter();
    Now inside the function PlayOneGame() you have solution and guess two char variables.
    Instead of using letter you should use solution.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to call this function with correct arguments?
    By SLiam in forum C Programming
    Replies: 13
    Last Post: 09-14-2013, 01:17 PM
  2. arguments of functions
    By SCRIPT_KITTEH in forum C Programming
    Replies: 2
    Last Post: 06-05-2013, 07:04 PM
  3. Replies: 8
    Last Post: 05-27-2013, 06:43 PM
  4. Functions as arguments
    By jw232 in forum C++ Programming
    Replies: 2
    Last Post: 04-19-2008, 11:11 AM
  5. a program that will call an execute but with arguments
    By what3v3r in forum C++ Programming
    Replies: 3
    Last Post: 01-19-2006, 09:44 PM

Tags for this Thread