Too Few Arguments

This is a discussion on Too Few Arguments within the C++ Programming forums, part of the General Programming Boards category; Code: #include <iostream> #include <stdio.h> using namespace std; char GetUserInput(void) { char Input; cout << "Input Residue Sequence: "<< endl; ...

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    82

    Too Few Arguments

    Code:
    #include <iostream>
    #include <stdio.h>
    
    using namespace std;
    
    
    char GetUserInput(void)
    
    {
    char Input;
    
    
    
        cout << "Input Residue Sequence: "<< endl;
        cin >> Input;
        return Input; //Returns a copy of Input
    }    
    
    char GetInputChange(char theInput)
    
    {
     cout << "WOOORK"<< endl;
     cout << theInput << endl;
     cin.get();
     
     return (theInput);
              
    }    
    
    int main (int argc, char* argv[]) 
    
    {
        
        GetUserInput ();
        
        GetInputChange();
     
    cin.get(); 
    }
    Need some help, i don't know what results in getting the error, "To few Arguments for Function Char GetInputChange"

    Just don't quite understand what the damn thing wants

    Edit for mistake thnks
    Last edited by Cdrwolfe; 06-29-2006 at 04:53 PM.

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,340
    The error is probably Too few arguments for GetInputChange, not GetUserInput. The GetInputChange function takes a single argument, but when you call it in main you don't pass anything to it. When calling a function that takes an argument, you must pass it something. In this case, you probably want to store the char returned from GetUserInput and pass that variable to GetInputChange.

  3. #3
    Registered User
    Join Date
    Oct 2005
    Posts
    82
    Hmm,

    I'd hoped that the first function would just take user input, single char and store it in variable "Input", return Input keeping it for use to other functions?

    and then the second function(GetInputChange) would be able to get what is in Input and just print it out ie (cout << theInput)

    I thought placing "theInput" into the functions Header allowed it to be called for cout.

    Am I going about this wrong?

    Thanks for the help

  4. #4
    Registered User
    Join Date
    Oct 2005
    Posts
    82
    Got it to compile thanks.

    Did what i thought you ment, but i could be wrong.

    Code:
    int main (int argc, char* argv[]) 
    
    {
        
        GetUserInput ();
        
        char Input = GetUserInput();
        
        GetInputChange(Input);
        
     {
             return Input;
     }
         
    cin.get(); 
    }
    Will now move on to getting If/Else in now

  5. #5
    semi-colon generator ChaosEngine's Avatar
    Join Date
    Sep 2005
    Location
    Chch, NZ
    Posts
    597
    close, but not quite

    Code:
    int main (int argc, char* argv[]) 
    
    {
        
        GetUserInput ();
        
        char Input = GetUserInput();
        
        GetInputChange(Input);
    
    // don't need these lines.
    /*    
     {
             return Input;
     }
       */  
    cin.get(); 
    }
    "I saw a sign that said 'Drink Canada Dry', so I started"
    -- Brendan Behan

    Free Compiler: Visual C++ 2005 Express
    If you program in C++, you need Boost. You should also know how to use the Standard Library (STL). Want to make games? After reading this, I don't like WxWidgets anymore. Want to add some scripting to your App?

  6. #6
    I am me, who else?
    Join Date
    Oct 2002
    Posts
    250
    Don't you need to put a return 0; at the end?
    Since that won't even compile without some return statement... or shouldn't anyway.

  7. #7
    The Richness... Richie T's Avatar
    Join Date
    Jan 2006
    Location
    Ireland
    Posts
    469
    slow down, you're not there yet - I assume that the below is what
    your code looks like now - read comments:


    Code:
    #include <iostream>
    #include <stdio.h>
    
    //<stdio.h> is a C header - the C++ version is <cstdio>, but you
    //don't need it in the program so there's no point in that include
    
    using namespace std;
    
    
    char GetUserInput(void)
    
    {
    char Input;
    
    
    
        cout << "Input Residue Sequence: "<< endl;
        cin >> Input;
        return Input; //Returns a copy of Input
    }    
    
    char GetInputChange(char theInput)
    
    {
     cout << "WOOORK"<< endl;
     cout << theInput << endl;
     cin.get();
     
     return (theInput); // why are you returning the parameter you passed?
              
    }    
    
    //int main (void) would suffice - this version is to allow 
    //command line arguments - more complicated than your level
    int main (int argc, char* argv[]) 
    
    {
        
        GetUserInput (); //unnecessary call here - you throw away the return value here
        
        //and then calling it properly here
        char Input = GetUserInput();
        
        GetInputChange(Input);
        
     {//unnecessay braces here
             return Input; //Input is a char - main returns int
     }//and here
         
    cin.get(); 
    }
    @dpro - Chaos is correct - compiler will automatically put in return
    0 if you leave it out.
    No No's:
    fflush (stdin); gets (); void main ();


    Goodies:
    Example of fgets (); The FAQ, C/C++ Reference


    My Gear:
    OS - Windows XP
    IDE - MS Visual C++ 2008 Express Edition


    ASCII stupid question, get a stupid ANSI

  8. #8
    Registered User
    Join Date
    Oct 2005
    Posts
    82
    Just realised it didn't actaually print out "Wooork"

    Thanks for the heads up

  9. #9
    Registered User
    Join Date
    Oct 2005
    Posts
    82
    Thanks Both of you,

    return (theInput); // why are you returning the parameter you passed?
    Sorry mistake from copying above functions return, don't quite know why i did it there.

    //int main (void) would suffice - this version is to allow
    //command line arguments - more complicated than your level
    int main (int argc, char* argv[])
    Force of habit from this c++ book i read/copy from, everything else has it in so i add it to be sure.

    GetUserInput (); //unnecessary call here - you throw away the return value here
    I thought it was needed to call function, wasn't sure (char Input = GetUserInput() called it again, until i realised now why two
    "Input Residue Sequence: " appeared


    return Input; //Input is a char - main returns int
    To be Honest i had no idea return was based on the functions type sadly , ie Int for main.

    Once again thanks all of you, a book just doesn't cut it in some areas, especially the original error.

  10. #10
    I am me, who else?
    Join Date
    Oct 2002
    Posts
    250
    Quote Originally Posted by Richie T
    @dpro - Chaos is correct - compiler will automatically put in return
    0 if you leave it out.

    Ah, well thats good, but for someone who is new, its always good to give a full picture whether or not its needed. Personally, its a little nit, but whatever works I suppose.

  11. #11
    semi-colon generator ChaosEngine's Avatar
    Join Date
    Sep 2005
    Location
    Chch, NZ
    Posts
    597
    Quote Originally Posted by dpro
    Ah, well thats good, but for someone who is new, its always good to give a full picture whether or not its needed. Personally, its a little nit, but whatever works I suppose.
    the other issue is that putting the "return input" in will skip the cin.get()

    Code:
    // original code
    int main (int argc, char* argv[]) 
    {
        
        GetUserInput ();
        
        char Input = GetUserInput();
        
        GetInputChange(Input);
    
     {
             return Input;
     }
    // after the return statement!!
    cin.get(); 
    }
    but yes, you're right. in general it is better to have a return 0 at the end of main.
    "I saw a sign that said 'Drink Canada Dry', so I started"
    -- Brendan Behan

    Free Compiler: Visual C++ 2005 Express
    If you program in C++, you need Boost. You should also know how to use the Standard Library (STL). Want to make games? After reading this, I don't like WxWidgets anymore. Want to add some scripting to your App?

  12. #12
    I am me, who else?
    Join Date
    Oct 2002
    Posts
    250
    Oh yes the return Input was in the wrong place, I meant at the end after cin.get(), but my point lacks any new information. So don't worry bout it Although technically it should be there, its not that big a deal.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beginner Needs help in Dev-C++
    By Korrupt Lawz in forum C++ Programming
    Replies: 20
    Last Post: 09-28-2010, 01:17 AM
  2. GradeInfo
    By kirksson in forum C Programming
    Replies: 23
    Last Post: 07-16-2008, 03:27 PM
  3. command line arguments
    By vurentjie in forum C Programming
    Replies: 3
    Last Post: 06-22-2008, 06:46 AM
  4. NULL arguments in a shell program
    By gregulator in forum C Programming
    Replies: 4
    Last Post: 04-15-2004, 10:48 AM
  5. registry, services & command line arguments.. ?
    By BrianK in forum Windows Programming
    Replies: 3
    Last Post: 03-04-2003, 01:11 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21