Thread: Too few arguments to function - Trouble with functions

  1. #1
    Registered User
    Join Date
    Apr 2014
    Posts
    4

    Too few arguments to function - Trouble with functions

    I am trying to create a program that will take a number you give to the input and then it will check through my calc() function what number it is then prints it out as a string from the integer you gave it. I am new to this so can anyone help me with my code?

    Error: Too few arguments to function

    p.s Tip would be greatly appreciated. I am not sure if I am doing my functions correctly


    Code:
    #include <iostream>
    
    using namespace std;
    // Function prototype
    int zero(int x);
    int one_through_nine(int x);
    int tenUp(int x);
    int twenties(int x);
    int calc(int x);
    
    int main()
    {
        // Take input
        int result;
        cout << "Enter number: " << endl;
        cin >> result;
    
        // Run input through calc function
        cout << calc(result);
        return 0;
    }
    
    
    // Returns 0
    int zero(int x){
        if(x < 1){
            cout << "zero";
        }
        return x;
    }
    
    // Returns 1 - 9
    int one_through_nine(int x){
        if(x == 1){
            cout << "one";
        }else if(x == 2){
            cout << "two";
        }else if(x == 3){
            cout << "three";
        }else if(x == 4){
            cout << "four";
        }else if(x == 5){
            cout << "five";
        }else if(x == 6){
            cout << "six";
        }else if(x == 7){
            cout << "seven";
        }else if(x == 8){
            cout << "eight";
        }else if(x == 9){
            cout << "nine";
        }
        return x;
    }
    
    // Returns 10 - 20
    int tenUp(int x){
        if(x == 10){
            cout << "ten";
        }else if(x == 11){
            cout << "eleven";
        }else if(x == 12){
            cout << "twelve";
        }else if(x == 13){
            cout << "thirteen";
        }else if(x == 14){
            cout << "fourteen";
        }else if(x == 15){
            cout << "fifteen";
        }else if(x == 16){
            cout << "sixteen";
        }else if(x == 17){
            cout << "seventeen";
        }else if(x == 18){
            cout << "eighteen";
        }else if(x == 19){
            cout << "eleven";
        }
        return x;
    }
    
    // Returns numbers 20 - 29
    int twenties(int x){
        if(x == 20){
            cout << "twenty";
        }else if(x < 30){
            cout << "twenty -" << one_through_nine();
        }
        return x;
    }
    
    // Calculates what function x will be put through
    int calc(int x){
        if(x == 0){
            cout << zero(x);
        } else if(x < 10){
            cout << one_through_nine(x);
        }else if(x < 20){
            cout << tenUp(x);
        }else if (x < 30){
            cout << twenties(x);
        }else{
            cout << "Numbers are under construction.\nSorry for the inconvenience." << endl;
            return x;
        }
        return x;
    }

  2. #2
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    Focus on lines 33, 87 and 97 and tell me where is the problem.

    Welcome in the forum.
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  3. #3
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Unrelated to your problem, but line 76-77 will also cause confusion for users.

    Overall: an unnecessarily contorted way to print out integral values as words.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  4. #4
    Registered User
    Join Date
    Apr 2014
    Posts
    4
    Thank you very much for your help guys

    I had changed up my twenties function to a twntUp so I can just go through the rest of the ten digits until I hit 100. I also added a x -= 20; to the same function so it can just add one-nine when it hits over 20.

    but now I am having an issue that after it prints what I was looking for it gives me 3 to 2 0's after my output. I am wondering if it is my program or my cmd line.

    My command line keeps acting funky if I do a loop up to 100, it will only show me from 98 or 97 and sometimes 73 does the command line usually do things like that?

    Grumpy: "Overall: an unnecessarily contorted way to print out integral values as words."
    Should I be doing loops instead or switch statements?

    Code:
    #include <iostream>
    
    using namespace std;
    // Function prototype
    int zero(int x);
    int one_through_nine(int x);
    int tenUp(int x);
    int twntUp(int x);
    int calc(int x);
    
    int main()
    {
        // Take input
        int result;
        cout << "Enter number: " << endl;
        cin >> result;
    
        // Run input through calc function
        cout << calc(result);
        return 0;
    }
    
    
    // Returns 0
    int zero(int x){
        if(x < 1){
            cout << "zero";
        }
        return 0;
    }
    
    // Returns 1 - 9
    int one_through_nine(int x){
        if(x == 1){
            cout << "one";
        }else if(x == 2){
            cout << "two";
        }else if(x == 3){
            cout << "three";
        }else if(x == 4){
            cout << "four";
        }else if(x == 5){
            cout << "five";
        }else if(x == 6){
            cout << "six";
        }else if(x == 7){
            cout << "seven";
        }else if(x == 8){
            cout << "eight";
        }else if(x == 9){
            cout << "nine";
        }
        return 0;
    }
    
    // Returns 10 - 20
    int tenUp(int x){
        if(x == 10){
            cout << "ten";
        }else if(x == 11){
            cout << "eleven";
        }else if(x == 12){
            cout << "twelve";
        }else if(x == 13){
            cout << "thirteen";
        }else if(x == 14){
            cout << "fourteen";
        }else if(x == 15){
            cout << "fifteen";
        }else if(x == 16){
            cout << "sixteen";
        }else if(x == 17){
            cout << "seventeen";
        }else if(x == 18){
            cout << "eighteen";
        }else if(x == 19){
            cout << "nineteen";
        }
        return 0;
    }
    
    // Returns numbers 20 - 29
    int twntUp(int x){
    
        if(x == 20){
            cout << "twenty";
        }
        if(x < 30){
            cout << "twenty-";
            x -= 20;
            cout << one_through_nine(x);
        }
        return 0;
    }
    
    // Calculates what function x will be put through
    int calc(int x){
        if(x == 0){
            cout << zero(x);
        } else if(x < 10){
            cout << one_through_nine(x);
        }else if(x < 20){
            cout << tenUp(x);
        }else if (x < 30){
            cout << twntUp(x);
        }else{
            cout << "Numbers are under construction.\nSorry for the inconvenience." << endl;
        }
        return 0;
    }

  5. #5
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Quote Originally Posted by NFlores2 View Post
    Grumpy: "Overall: an unnecessarily contorted way to print out integral values as words."
    Should I be doing loops instead or switch statements?
    Depends. I suspect by answering that question, I'd be doing your homework, which would breach this site's homework policy. So I won't. Instead, I'll give you some food for thought.

    Firstly, let's say you want your program to be able to print out words for every value between 1 and 100000. Are you really going to implement all 100000 cases individually??? Because that is essentially your approach so far.

    As a hint, for example, an equivalent of your function one_through_nine() could be implemented using an array definition and a single if statement. And, with a relatively minor change, that function could handle all cases up to 19.

    You might also want to consider the difference in logic needed to print 43 as words and to print 63 as words. Put it this way: is there any common logic between those?
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 02-04-2013, 04:28 PM
  2. trouble passing arguments to method
    By Dale in forum C# Programming
    Replies: 8
    Last Post: 12-02-2011, 12:40 PM
  3. Defining functions in C and using function arguments
    By Bluesilver2009 in forum C Programming
    Replies: 14
    Last Post: 10-28-2009, 01:29 PM
  4. trouble with arguments in main method
    By vopo in forum C Programming
    Replies: 3
    Last Post: 07-15-2007, 10:14 PM