C++ Program:

- To toggle string cases

Example:

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;
    else if(s1[i]>='A' && s1[i]<='Z')
      s1[i]+=32;
  }
  cout<<"After toggle, Your string : "<<s1;
  return 0;
}

Output:

  Enter your string : Have good DAy
  After toggle, Your string : hAVE GOOD daY
Program
string

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++) {
  if(s1[i]>='a' && s1[i]<='z') {     //Check for lowercase
    s1[i]-=32;  //convert it to uppercase & store it back
  }
  else if(s1[i]>='A' && s1[i]<='Z') {    //Check for uppercase
    s1[i]+=32;     //covert it to lowercase & store it back
  }
}
  
Concept

Coming Soon !

Quick
Tutorial

Quote

Find a place inside where there’s joy, and the joy will burn out the pain.