Note that there are some explanatory texts on larger screens.

plurals
  1. POCannot input more than one string in palindrome program
    primarykey
    data
    text
    <pre><code>#include &lt;iostream&gt; #include &lt;ctype.h&gt; using namespace std; void isPalindrome(); int main() { char response; isPalindrome(); cout &lt;&lt; "Input another string(y/n)?" &lt;&lt; endl; cin &gt;&gt; response; response = toupper(response); if (response == 'Y') isPalindrome(); return 0; } void isPalindrome() { char str[80], str2[80]; int strlength; int j = 0; int front, back; bool flag = 1; cout &lt;&lt; "Input a string:" &lt;&lt; endl; cin.getline(str, 80); strlength = strlen(str); for (int i = 0; i &lt; strlength; i++) { if (islower(str[i])) str[i] = toupper(str[i]); } for (int i = 0; i &lt; strlength; i++) { if (isalpha(str[i])) { str2[j] = str[i]; j++; } } str2[j] = '\0'; front = 0; back = strlength - 1; for (int i = 0; i &lt; j / 2; i++) { if (str2[front] != str2[back]) { flag = 0; break; } } if (!(flag)) cout &lt;&lt; "It is not a palindrome" &lt;&lt; endl; else cout &lt;&lt; "It's a palindrome" &lt;&lt; endl; cout &lt;&lt; "str: " &lt;&lt; str &lt;&lt; " str2: " &lt;&lt; str2 &lt;&lt; " strlength: " &lt;&lt; strlength &lt;&lt; " j: " &lt;&lt; j &lt;&lt; endl; cout &lt;&lt; "front: " &lt;&lt; front &lt;&lt; " back: " &lt;&lt; back &lt;&lt; " flag: " &lt;&lt; flag &lt;&lt; endl; } </code></pre> <p>I was just wondering if anybody could help explain to me why my code isn't working.</p> <p>I can run it once just fine and I get the right answer, but when the prompt asks if I want to input another string and I type <code>'y'</code>, the prompt just skips over the input and terminates on it's own.</p> <p>I tried <code>cin.ginore('\n', 80)</code>, but that just gave me a bunch of blank lines. I added the bit of code at the end to check the values and they all go to <code>0</code> and drop the strings.</p> <p>Maybe a link to a proper explanation of how the system handles memory?</p> <p>edit: I keep getting the same problem when running the input sequence a second time. The output looks like this: </p> <pre><code> Input a string: Radar It's a palindrome Input another string(y/n)? y _ &lt;- this being my cursor after pressing enter 3 times </code></pre> <p>I'll just re-build the program from scratch and try to do it without a function. I'd still appreciate a link to a page that explains how to process user input using modern c++.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload