Tests the user's first initial and prints a message. - C++ Language Basics

C++ examples for Language Basics:Console

Description

Tests the user's first initial and prints a message.

Demo Code

#include <iostream>
using namespace std;
int main()//from w w w  .j  av a  2 s.  c o m
{
   char last[20];   // Holds the last name.
   cout << "What is your last name? ";
   cin >> last;
   // Test the initial
   if (last[0] <= 'P')
   {
      cout << "Your name is early in the alphabet.\n";
   }
   else
   {
      cout << "You have to wait a while for " << "YOUR name to be called!\n";}
      return 0;
}

Result


Related Tutorials