I'm asked to write a program in which the user inputs a letter and the program converts it to lower case if it's UPPER and vis versa.
I have written this program and it worked:
#include<iostream>
using namespace std;
int main()
{
char letter;
cout<<"Enter any letter"<<endl;
cin>>letter;
if(letter>=97&&letter<=122)
{
letter=letter-32;
cout<<"The UPPER CASE letter is: "<<letter<<endl;
}
else
{
letter=letter+32;
cout<<"The lower case letter is: "<<letter<<endl;
}
system("pause");
return 0;
}
my proplem is that someone told me about another way to write this program but I can't understand what did he use!
which is:
#include<iostream>
using namespace std;
int main()
{
char x;
cout<<"Enter any letter"<<endl;
cin>>x;
cout<<(x=(x>='A'&&x<='Z')?x+=' ':x-=' ')<<endl;
return 0;
}
I want to know how it works?!
Thanks alot.