C++ examples for Data Type:char
Determines whether the user typed a G or a B.
#include <iostream> using namespace std; #include <conio.h> #include <ctype.h> void main()/*w ww. ja v a 2s .com*/ { char ans; cout << "Are you a girl or a boy (G/B)? "; ans=getch(); getch(); cout <<ans<<"\n"; ans = toupper(ans); switch (ans) { case ('G'): { cout << "You look pretty today!\n"; break; } case ('B'): { cout << "You look handsome today!\n"; break; } default : { cout << "Your answer makes no sense!\n"; break; } } return; }