Determines whether the user typed a G or a B. - C++ Data Type

C++ examples for Data Type:char

Description

Determines whether the user typed a G or a B.

Demo Code

#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;
}

Result


Related Tutorials