C - Print Title Miss or Mr Based on Gender with Name using C Program.


IncludeHelp 14 August 2016

In this code snippet we will learn how to print title like Mr or Miss with entered name; title will be recognised through entered value of gender.

If you enter gender (M or m) name will be printed with Mr and if you enter gender (F or f) name will be printed with Miss.

If you enter gender except of M,m,F,f name will be printed with N/A title.

C Code Snippet - Print Title (Miss or Mr) based on Gender with Name

/*C - Print Title Miss or Mr Based on 
Gender with Name using C Program.*/

#include <stdio.h>

int main(){
	char name[40];
	char gender;
	
	printf("Enter name: ");
	gets(name);
	printf("Enter gender (M/F): ");
	scanf("%c",&gender);
	
	if(gender=='m'||gender=='M')
		printf("Hello Mr. %s.\n",name);
	else if(gender=='f'||gender=='F')
		printf("Hello Miss %s.\n",name);
	else
		printf("Hello N/A %s.\n",name);
	
	return 0;	
}

    First Run:
    Enter name: Mike
    Enter gender (M/F): M
    Hello Mr. Mike.

    Second Run:
    Enter name: Angel Princy
    Enter gender (M/F): F
    Hello Miss Angel Princy.

    Third Run:
    Enter name: Princem
    Enter gender (M/F): U
    Hello N/A Princem.



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.