Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Feb 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Illegal function definitions in "DoYouLikeThree()" (Still not solved!!!)

    Hello, I am having some problems with this piece of code.
    Code:
    char User_Decision;
    	void DoYouLikeThree(){
    		cout << "Do you like the number 3? (Yes=Y, No=N)" << endl;
    		cin >> User_Decision;
    		if (User_Decision=y){
    		cout << "You are cool" << endl;
    		}
    		else {
    			if (User_Decision=n)
    				cout << "You are uncool" << endl;
    		}
    		
    	}
    What am I doing wrong? (This is just a portion of the program, I have #include <iostream> which should have all the definitions for cout, etc.
    Last edited by mero42; 02-19-2005 at 11:12 PM.

  • #2
    Regular Coder
    Join Date
    Oct 2004
    Posts
    230
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Have you added the line "using namespace std" under "#include <iostream>"? You will need that or "using std::cout" and "using std::cin" to be able to use cin and cout.

    Once you get that working, you can search for the difference between "=" and "==", and also learn about comparing strings.

  • #3
    New to the CF scene
    Join Date
    Feb 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yeah, I have added using namespace std; and I noticed the == mistake and changed that...I don't know why I used a normal equal sign, I know that it is used in giving variables a value.

    I have other parts in that program that use "cout" and "cin," and they work just fine, so adding the std's at the top wont really fix anything.
    Last edited by mero42; 02-19-2005 at 10:30 PM.

  • #4
    Regular Coder
    Join Date
    Oct 2004
    Posts
    230
    Thanks
    0
    Thanked 0 Times in 0 Posts
    As long as you have something like "if (User_Decision == 'y')", that function should be fine.

    If you still get illegal function definition error, check the function above it for misplaced/missing braces.

  • #5
    New Coder
    Join Date
    Nov 2004
    Location
    Netherlands
    Posts
    87
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You might also want to check it with an toupper(), so it will respond correctly to both upper case and lower case values:

    Code:
    if(toupper(character) == 'Y') ;
    ...


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •