If-Else Statement

Hi guys, trying to sort out this code, i have to get the program to check whether input is UPPER case or lower case. It then must tell the user that the letter they entered was in lower case or UPPER case.

So far i have:

#include <iostream>
using namespace std;

int main ()

{

char letter;

cout << "Please type a letter: ";
cin >> letter;

if ('z'>=letter<='a')
{
cout << "Letter entered was lowercase. " << endl;
}
else
}
cout << "Letter is not in lower case format " << endl;
{
system ("pause");

return 0;
}


Any advice appreciated. thanks in advance.

Edit: forgot detail.
Last edited on
instead of bolding your code, put it in a code tag (see # symbol right above the Bold symbol)

Your braces after the else are backwards. You want this:
1
2
3
4
else
{
  // whatever
}
Ok. Update:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
using namespace std;

int main ()

{

     char letter;

     cout << "Please type a letter: ";
     cin >> letter;

  if ('a'>=letter<='z')
   {
     cout << "Letter entered was lowercase. " << endl;
   }
  else
   {
     cout << "Letter is not in lower case format " << endl;
   }
    system ("pause");

    return 0;
}


Still doesnt work. This is what im actually aiming to do with the program:

Write a c++ Program that accepts a character using the cin object and determine whether the character is a lowercase letter.

A lowercase letter is any character that is greater than or equal to a and less than or equal to z . If the entered character is a lower case letter, display the message The character just entered is a lowercase letter.

If the entered letter is not lowercase display The character just enetered is not a lowercase letter.


'a'>=letter<='z' should be
letter >= 'a' && letter <= 'z'

'a'>=letter<='z' would first evaluate 'a'>=letter to true or false (1 or 0) and then compare 1 or 0 with 'z', which it is less than
Last edited on
Ok, thanks for that. So what does the && operator actually do to the expression?
it means and, so if both letter >= 'a' is true and letter <= 'z' is true, it returns true, otherwise it returns false.

also, || means or. it returns true if one of the values is true, or if both are true. It only returns false if both are false.
Last edited on
Topic archived. No new replies allowed.