I need to convert all uppercase letters to lowercase and vice-versa. If one of the elements of the string is not a valid letter of the alphabet, it must be replaced with “bug here!”. Using user-defined function
Input: evEry1 Output: EVeRY*bug here!* I am already able to convert all uppercase letters to lowercase and vice-versa. I was also able to change nonalphanumeric elements to a single character but cannot replace it with the entire string "bug here!". I end up having error saying it cannot be converted
string flip (string w, int t){ string ch = "*bug here!*"; for (int j=0; j<w.length(); j++){ if (w[j] >= 'A' && w[j] <= 'Z') w[j] = w[j] + 32; else if (w[j] >= 'a' && w[j] <= 'z') w[j] = w[j] - 32; else w[j] = ch; } return w; }
w[j] = ch;. Instead you should use the stringreplacemethod.int tas a parameter?+ 32, use- 'A' + 'a'. Or, better,tolower().