I am writing a function which will check if the letter is in upper case , if so it returns true otherwise false.
Following is the code, I have written, but what is wrong?

#include<iostream>


using namespace std;


using std::cout;
using std::cin;
using std::endl;


int isUpperCase ( char );


int main()


{
int i;
char c;


cout<<"Enter a charactor : ";
cin>>c;


i = int ( c );


isUpperCase ( i );



return 0;



}


int isUpperCase ( i )


{
if ( i > 65 && i < 90 )


return 1;


else


return 0;


}

please comment.

Edited 3 Years Ago by happygeek: fixed formatting

How about...

#include <iostream>
#include <string>

using namespace std;

class Foo
{
public:
   bool isUpperCase( char t )
   {
     string crap = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
     int size = crap.length();
     
      // check if the same return true 
     //otherwise return false

};


int main()
{ 
  Foo test;
  cout << test.isUpperCase('a') << endl;
  
  cout << test.isUpperCase('A');
  
  cin.get();
}

hi,
you can also mask bit on position# 6, which is 0 if char is upper case and 1 if char is lower case, e.g. 'A' = 0x41 = 0100 0001 (binary), 'a' = 0x61 = 0110 0001 (binary).

bool isUpperCase (char c) {return !(c&0x20);}
. . .
char c='z';
cout<<c<<(isUpperCase(c)?" is upper ":" is lower ")<<"char";
// z is lower char

krs,
tesu

I see nothing wrong with the function isUpperCase except from what mitrmkar sead, it would not work if you passed the function the characters 'A' or 'Z'.

This article has been dead for over six months. Start a new discussion instead.