- To convert string into UPPERCASE
User Input: hello World
Output: HELLO WORLD
#include <iostream>
using namespace std;
int main() {
string s1;
cout<<"Enter your string : ";
getline(cin,s1);
for(int i=0;i<s1.length();i++) {
if(s1[i]>='a' && s1[i]<='z')
s1[i]-=32;
}
cout<<"Your uppercase string : "<<s1;
return 0;
}
Enter your string : Have good day Your uppercase string : HAVE GOOD DAYProgram
You should know first :
Lowercase alphabets : Starts from a (97) to z (122)
Uppercase alphabets : Starts from A (65) to z (90)
for(int i=0;i<s1.length();i++) {
//Check for lowercase
if(s1[i]>='a' && s1[i]<='z')
s1[i]-=32; //convert it to uppercase & store it back
}
for(int i=0;i<s1.length();i++) {
//Check for uppercase
if(s1[i]>='A' && s1[i]<='Z')
s1[i]+=32; //covert it to lowercase & store it back
}
Concept