**Discussion 4**
09/15, 09/17
[(back to course webpage)](./mcs360_fall2020.html)
# Problem 1
Write a CPP program that asks the user to input a string and reverses the string as output. Then it asks the user if they want to continue entering more strings, and if not, the program ends. Otherwise it asks the user to enter a string again.
## Example run
```
Enter a string to reverse: abcdEf
String in reverse: fEdcba
Do you want to continue(Y/N)?: Y
Enter a string to reverse: alberio
String in reverse: oirebla
Do you want to continue(Y/N)?: N
Exiting.
```
## Solution
Solution
```cpp
#include
#include
int main() {
std::string inp;
char choice = 'Y';
while(choice == 'Y') {
std::cout << "Enter a string: ";
std::cin >> inp;
// need a for loop startin at the last entry and going back to the first
std::cout << "The string in reverse:";
for(int i = inp.length()-1; i >= 0; i--) {
std::cout << inp[i];
}
std::cout << std::endl;
std::cout << "Do you want to continue? (Y/N)";
std::cin >> choice;
}
std::cout << "Exiting.\n";
return 0;
}
```
# Problem 2
Write a CPP program that asks the user to input a string, and checks if it is palindrome or not.
## Example runs
```
Enter a string: abababa
String is palindrome.
```
```
Enter a string: cygnus
String is not a palindrome.
```
## Hints
Hint 1