Can someone help me im totally stumped

This is a discussion on Can someone help me im totally stumped within the C++ Programming forums, part of the General Programming Boards category; #include <iostream> #include <string> using namespace std; int main() Code: { string f= female; string m= male; string gender; cout ...

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    11

    Can someone help me im totally stumped

    #include <iostream>
    #include <string>
    using namespace std;

    int main()

    Code:
    {
     
        string f= female;
        string m= male;
    	string gender;	
    	
    	
    	cout <<"Please Enter Your Gender By Using M or F"<< flush;
    	cin  >> gender;
    	
    	cout << endl;
    
    	if ( gender >= M )
    
    	cout <<"Your Gender Is:"<<" "<<M<<endl;
    
        else 
    		cout <<"Are you female?"<<endl;
    
    return 0;
    
    }
    This is all i have and i know im totally wrong.. Whats my problem?? I can't think in my head how to do this..

    If the input is 'M' then the output should me "Male". If the gender is "F" then the output should be Female. And invalid gender otherwise.. I kinda gave up!!!!

  2. #2
    #include <me!> Flakster's Avatar
    Join Date
    May 2005
    Location
    Canada
    Posts
    50
    Your problem is that the operator >= is looking to see if 'gender' is greater then or equal to 'M'. The operator you want to use it == which checks to see if 'gender' is identical to 'M'.

  3. #3
    Unregistered User
    Join Date
    Sep 2005
    Location
    Antarctica
    Posts
    341
    compare the string gender to the string "M", if (gender == "M")

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Totally confused on assigment using linked lists
    By Uchihanokonoha in forum C++ Programming
    Replies: 8
    Last Post: 01-05-2008, 04:49 PM
  2. totally stumped
    By sand_man in forum C Programming
    Replies: 6
    Last Post: 08-22-2004, 08:12 PM
  3. Writing a "Protocol" - Stumped.
    By mrpickle in forum Game Programming
    Replies: 8
    Last Post: 01-21-2004, 07:37 PM
  4. help with stl search/find, or something else- stumped!
    By Terranc in forum C++ Programming
    Replies: 3
    Last Post: 12-21-2002, 04:11 PM
  5. Everyone look at my totally sweet spaceship
    By Shadow12345 in forum Game Programming
    Replies: 4
    Last Post: 09-30-2002, 03:27 PM

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