is a simple game, which function is to reverse all possible input from the user.
content:
reverse_string can handle introducing itself to the player:
reverse_string is producing results right avay, after input is submitted. Results are executed by a for loop, combined with printing statement for current character. Printing is strating from the very last character.
code
for (int index = lastIndex; index > -1; index--) //starting from the last index and print each letter untill index is more than -1 { Console.Write(initialInput[index]); //displaying the reversed order character by character
quick tip: palindrome
The reverse_string game has a hidden feature which is revealed when input is a palindrome. Detection is executed by if statement, to introduce a condition. Condition is checking whether last character is not equal to the first character, and so on, looping through input in both directions, comparing ascending order with the descending order of characters. When at least 1 pair of characters is not equal to each other - it is not a plalindorme. The isPalindrome variable is set to false. As a result - user is only getting the reversed input. Nothing else is printed. When if consition is never executed - which means that all pairs of letters from input are equal - the
Yay, found a Palindrome!
message is printed additionally for user.
code
if (initialInput[index] != initialInput[lastIndex - index]) // palindrome check - if letter from the end not equal to letter from the beginning { isPalindrome = false; //when at least 1 letter is not equal - isPalindrome switches to false }
reverse_string Palindrome detection: