Thread: calling a function inside main()

  1. #1
    Registered User
    Join Date
    Feb 2005
    Posts
    18

    Question calling a function inside main()

    I am having more troubles in my future reference program...
    I have this function:

    Code:
    char User_Choice;
    	void userDecision(char User_Choice) {
    	std::cout << "Do you like the number 3? Yes=Y, No=N" << endl;
    	std::cin >> User_Choice;
    	if (User_Choice == 'y') {
    		std::cout << "You are cool." << endl;
    	}
    	else if (User_Choice == 'n'){
    		std::cout << "You suck!" << endl;
    	}
    	else if (User_Choice != 'y' && User_Choice != 'n'){
    		std::cout << "Invalid Decision" << endl;
    	}
    
    	}
    And I need to invoke/call it inside the function main().
    I am trying to do it like this:
    Code:
    userDecision(char User_Decision);
    But it's not working...any help?

  2. #2
    Handy Andy andyhunter's Avatar
    Join Date
    Dec 2004
    Posts
    540
    I think I see what you are doing but it is kindof hard without the complete code.

    Why don't you have a look at this tutorial on functions and see if that clears up your problems.
    i don't think most standard compilers support programmers with more than 4 red boxes - Misplaced

    It is my sacred duity to stand in the path of the flood of ignorance and blatant stupidity... - quzah

    Such pointless tricks ceased to be interesting or useful when we came down from the trees and started using higher level languages. - Salem

  3. #3
    Registered User
    Join Date
    Feb 2005
    Posts
    18
    No, that really didn't help me much...
    I just need to know how to use a function inside of main().

  4. #4
    Registered User
    Join Date
    Feb 2005
    Posts
    18
    The error i am getting is this: "function does not take zero arguments."

  5. #5
    Registered User
    Join Date
    Feb 2005
    Posts
    18
    Ok, I got it to work...the argument I put in the function had no point, therefore it was invalid.

  6. #6
    Slave MadCow257's Avatar
    Join Date
    Jan 2005
    Posts
    735
    That means that you are calling a function that takes 1 or more parameters, but you are giving it none. If you can't spot the error yourself, then post more code and we'll find it for you.

    EDIT
    k, nvr mind

  7. #7
    Registered User
    Join Date
    Nov 2003
    Posts
    183
    if you send your full program we could help you more .
    Code:
    void userDecision(char User_Choice)
    it means userdecision takes a char when it is called .
    for calling the function you have written :
    Code:
    userDecision(char User_Decision);
    (there is no need to write the type ( char ) before arguman name )

    what is user_decision ?
    if it is user_choice then why you read it in function userdecision again ?
    I think you want to read user_choice in main and send it to ur function for doing this :

    in main ->
    Code:
        std::cout << "Do you like the number 3? Yes=Y, No=N" << endl;
        std::cin >> User_Choice;
        userDecision(User_choice);
    and your function be ->
    Code:
    void userDecision(char User_Choice) {
         if (User_Choice == 'y') {
            std::cout << "You are cool." << endl;
        }
        else if (User_Choice == 'n'){
            std::cout << "You suck!" << endl;
        }
        else if (User_Choice != 'y' && User_Choice != 'n'){
            std::cout << "Invalid Decision" << endl;
        }
    
        }
    hope it helps

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. having some trouble calling a function in the main program
    By CMakesMeSad :( in forum C Programming
    Replies: 19
    Last Post: 06-26-2009, 09:33 PM
  2. In over my head
    By Shelnutt2 in forum C Programming
    Replies: 1
    Last Post: 07-08-2008, 06:54 PM
  3. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  4. Return Statement
    By Daveo in forum C Programming
    Replies: 21
    Last Post: 11-09-2004, 05:14 AM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM