Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Write a program to read gender m/f and print corresponding gender

0 votes
asked Feb 21, 2019 by Shyzer Betty (120 points) 1 flag

3 Answers

0 votes
answered Feb 21, 2019 by anonymous 1 flag
#include <stdio.h>

int main()
{
    char gender;

    printf("Enter gender (M/m or F/f): ");
    scanf("%c",&gender);

    switch(gender)
    {
        case 'M':
        case 'm':
            printf("Male.");
            break;
        case 'F':
        case 'f':
            printf("Female.");
            break;
        default:
            printf("Unspecified Gender.");
    }
    printf("\n");
    return 0;
}
+1 vote
answered Feb 22, 2019 by Jerold Callistus
#Using Python:

gender = input("Please enter your Gender : ")

if (gender == "M" or gender == "m" or gender == "Male" or gender == "male"):
    print("The gender in Male")
elif (gender == "F" or gender == "f" or gender == "FeMale" or gender == "Female" or gender == "feMale" or gender == "female"):
    print("The gender is Female")
else:
    print("Please provide an appropriate format")
0 votes
answered Feb 22, 2019 by Mutongi Takesure Chauke
edited Feb 22, 2019
import java.util.Scanner;
/**
 *
 * @author MutongiChaukeTakesure
 */
public class Sex {

    static String sex;
    static String M = "mALe";
    static String F = "FeMaLE";

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner in = new Scanner(System.in);
        System.out.println("Enter your sex here:");
        sex = in.nextLine();

        if (sex.equalsIgnoreCase(M) || sex.equalsIgnoreCase("m")) {
            System.out.print("male");
        } else if (sex.equalsIgnoreCase(F) || sex.equalsIgnoreCase("f")) {
            System.out.print("female");
        }

    }

}
commented Sep 21, 2019 by Matimba
java is more powerful!
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...