Thread: What is wrong with my code?

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    1

    Question What is wrong with my code?

    //Ask user to input # of a num
    //Check for legal input
    //Print out:
    //The name of the num is _____ .

    Code:
    #include 
    using namespace std; 
    
    
    int main() 
    { 
    	int num; 
    
    	cout<<"Please enter the number of a month: "; 
    	cin>>num; 
    	
    	if ( (num < 1 ) || (num > 12) ) 
    		cout<<"That’s not the number of a month. "<<endl; 
    	else 
    	{ 
    		cout<<"The name of the month is: "; 
    
    		if (num == 1) 
    			cout<<"January"; 
    		else if (num == 2) 
    			cout<<"February"; 
    		else if (num == 3) 
    			cout<<"March"; 
    		else if (num == 4) 
    			cout<<"April"; 
    		else if (num == 5) 
    			cout<<"May"; 
    		else if (num == 6) 
    			cout<<"June"; 
    		else if (num == 7) 
    			cout<<"July"; 
    		else if (num == 8) 
    			cout<<"August"; 
    		else if (num == 9) 
    			cout<<"September"; 
    		else if (num == 10) 
    			cout<<"October"; 
    		else if (num == 11) 
    			cout<<"November"; 
    		else 
    			cout<<"December"; 
    
    		cout<<"."<<endl; 
    	} 
    
    return 0; 
    
    }
    
    
    It will not execute.  It is saying that I have one error.
    &#91;code]&#91;/code]tagged by Salem
    Last edited by kewee7197; 10-10-2002 at 09:17 AM.

  2. #2
    Registered User
    Join Date
    Jun 2002
    Posts
    82
    Well, you don't have any header file name after your #include statement...once I corrected that to #include <iostream> the code compiled without error and appears to function properly. Maybe if you posted the error message?
    Claus Hetzer
    Compiler: Borland 5.5 (on Windows)
    Solaris CC (on Unix)
    Known Languages: C++, MATLAB, Perl, Java

  3. #3
    TransparentMember correlcj's Avatar
    Join Date
    Jun 2002
    Posts
    378

    Question

    It is saying that I have one error.
    What error are you getting?

    I see you forgot something.
    #include <what?>

    I know you need <iostream> for using cin, cout, << , >>
    Maybe thats your problem if not at least one problem has been solved.
    I hope this helps. pls let me know.
    Last edited by correlcj; 10-11-2002 at 06:43 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. what is wrong in this simple code
    By vikingcarioca in forum C Programming
    Replies: 4
    Last Post: 04-23-2009, 07:10 AM
  2. what is wrong with this code please
    By korbitz in forum Windows Programming
    Replies: 3
    Last Post: 03-05-2004, 10:11 AM
  3. I cant find what is wrong with this code
    By senegene in forum C Programming
    Replies: 1
    Last Post: 11-12-2002, 06:32 PM
  4. Anyone see what is wrong with this code?
    By Wise1 in forum C Programming
    Replies: 2
    Last Post: 02-13-2002, 02:01 PM
  5. very simple code, please check to see whats wrong
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 10-10-2001, 12:51 AM