Need help

This is a discussion on Need help within the C++ Programming forums, part of the General Programming Boards category; Whats wrong with this? Code: /*****************************/ /* Program v1.0 */ /*****************************/ /* Written by Brian */ /* brian_denys@hotmail.com */ /* ...

  1. #1
    Registered User
    Join Date
    Jul 2007
    Posts
    61

    Need help

    Whats wrong with this?

    Code:
    /*****************************/
    /*        Program v1.0       */
    /*****************************/
    /*      Written by Brian     */
    /*  brian_denys@hotmail.com  */
    /*   http://ctte.php0h.com   */
    /*****************************/
    /*        Program.cpp        */
    /*****************************/
    
    #include <windows.h>
    #include <iostream>
    
    char YourName[] = "";
    char EyeColor[] = "";
    char EyeOne[] = "Brown";
    
    using namespace std;
    
    void main(){
    	cout << "Your name: " << endl;
    	cin >> YourName;
    	cout << "Eye color: " << endl;
    	cin >> EyeColor;
    	if(EyeColor == EyeOne){
    		cout << "beatiful" << endl;
    	}else{
    		cout << "ugly" << endl;
    	}
    }

  2. #2
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,262
    You can't use the == operator to compare character arrays. Use std::string instead of char[]'s. #include <string> too. If you can't ust std::string's (for assignment restriction reasons due to course or something), look into strcmp

  3. #3
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,892
    You have void main(). See the FAQ. You include windows.h for no reason. You don't allocate space for the input.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

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