Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how do i make the program read uppercase and lowercase as the same?

string C;
cin>>C;
if (C=="add" ){
    int a=add(A,B);
    cout<<a<<endl;

I have here a simple condition where i am taking input "C" to ask the user to write which math operation they want to run. The user might input in capital letters or the first letter might be uppercase and the rest be lowercase. What should I do so that the program reads all the inputs weather uppercase or lowercase as the same?

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Transform the user input into all lowercase or uppercase.

#include <algorithm>
#include <cctype>
#include <string>

std::string toLowerCase(const std::string& str) {
  std::string lower(str);
  std::transform(lower.begin(), lower.end(), lower.begin(), ::tolower);
  return lower;
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading