# String arrays exercise

 Gent Ymeri · May 15, 2015 Hi!First of all I want to introduce myself.My name is Gent and I come from Europe.I am a first year student doing a B.Sc in BusinessInformatics (in U.S is knows as Information Systems/ Information Technology as I know)In this semester I have started to learn programming and I have a question which I can't solve without errors, if you guys can help me solve it, I would be thankful. The question is about String Arrays. Allow user to enter one text, then: a) Print the entered text in reverse order. and b) in the reverse text replace each lower case letter with upper case and vice versa. Thank you in advance!

## Replies

 Sengngy Kouch · May 17, 2015 Hi there, nice to know you up here.First of all, instead asking people to give you the solution, why don't you show us what you got so far?Not to be rude, but if you are going to just ask people to give you the whole solution, you might consider dropping this major as it is going to be a lot more difficult.===================================================================Alright, enough said.1. I don't know if you already know how to get input from user. so here is how:First, make sure you have type #include in your file.Then.``string input;cout input; // this allow you to get input from user.``Remember that this only allow user to input a single string. Without any white space.  2.Print the entered text in reversed order.First of all, I think you should know how to use For loop, don't  you?and do you know how to use substr ?The main idea is to go through half way of the  "for loop"  and swap the right character with left character.Example.   your string is "ABCDE"so you need loop through the string half way by:``for ( int i = 0; i< input.length() / 2; i++){ // do the swap here.}``swapping is easy when you master it.``string temp;temp = leftSubstring;leftSubstring = rightSubString; // note: this is just a pseudo code, you need to use substr here.rightSubString = temp;``3.Replacing the case of the letter is easy.you need to type :  #include  then use thing line of code:``transform(input.begin(), input.end(), input.begin(), ::tolower); // from upper to lower.transform(input.begin(), input.end(), input.begin(), ::toupper); // from lower to upper.``I hope this help. Sengngy Kouch · May 17, 2015 I forget that this site won't allow me to use << in the code segment,so here it for #1.string input;cout << "Please input a string" << endl;cin >> input; // this allow you to get input from user. Gent Ymeri · May 18, 2015 Thank you! Even though I already solved the problem.Also, you are right, I should have written the code. The problem was that I didn't wrote the correct line of code for reversing the string, I knew the rest of the code how should it be done. it was  _strrev(text) which I didn't write for some reason during the lectures.Thank you for explaining me the things you did above. I also can see that I gave a wrong impression.. but, still thanks for taking your time and consideration to help me. the code you wrote about swapping, looks to me like kind bubble sort thing!? here is the code I wrote for the solution. Any feedback, would be appreciated. #include using namespace std;int main(){ char text[100]; cout << "Enter text:"; cin.getline(text, 100);_strrev(text); cout << "The text in reverse order is:" << text<
• 1

## C++

104,834 followers