Need some help with loops and converting a sentence of any size to uppercase, lowercase, and backwards display

The issue I'm having with menuSelect == 2 is that only position 0 in sentence converts to an uppercase rather than the entire sentence. With menuSelect == 3 only the the letter in position 0 converts to lowercase.

It doesn't really make sense the way you've laid out the program. Right now, it starts a loop for each index in the sentence. Then it asks you what command you want to do to the sentence. Then it does something to the sentence, and the loop repeats from there. So it repeatedly

Shouldn't you ask the user just once for a command, and then loop over each index in the sentence?

In menuSelect == 4 nothing happens because honestly I just have no idea how to display the sentence variable so that it appears backwards.

If I have a string test= "hello";

  • what's test.at(test.length() - 0)? and test.at(test.length())? error/exception. The point is that arrays (which strings basically are) go from 0 to length-1.

  • what's test.at(test.length() - 1)? o

  • what's test.at(test.length() - 2)? l

  • what's test.at(test.length() - 3)? l

  • what's test.at(test.length() - 4)? e

  • what's test.at(test.length() - 5)? and test.at(test.length() - test.length())? and test.at(0)? h

So think of the thing getting subtracted from test.length() as the index of a for loop. You start that index at 0 and go until that index reaches the length of the string.

/r/cpp_questions Thread