The If- else Construct in C++


The following, for example, program uses a nested if...else construct to check if the input character is uppercase or lowercase.

#include<iostream.h>

#include<conio.h>

int main()

{
  char inp;

  cout << "Please enter a character:";

  cin >> inp;

  if (inp >= 'A')

if (inp <= 'Z')

cout << endl << "uppercase";

else if (inp  >= 'a')

{
if (inp  <=  'z')

cout << endl << "Lowercase";

else

cout << endl << "Input character > z";
        }

else
{
cout << endl << "input character > z but less than a";
}
else
{
cout << endl << "input character less than A";
}
   return 0;

}

0 comments:

Post a Comment