Note that there are some explanatory texts on larger screens.

plurals
  1. POGet blank line after calling Palindrome function
    primarykey
    data
    text
    <p>So I have these two functions at the top of my program:</p> <pre><code>string deletespaces(string sentence){ sentence.erase(std::remove(sentence.begin(), sentence.end(), ' '), sentence.end()); return sentence; } </code></pre> <p>and</p> <pre><code>string checkpalindrome(string sentence){ deletespaces(sentence); if (sentence == string(sentence.rbegin(), sentence.rend())){ cout &lt;&lt; sentence &lt;&lt; " is a palindrome." &lt;&lt; endl; } if(sentence != string(sentence.rbegin(), sentence.rend())){ cout &lt;&lt; sentence &lt;&lt; " isn't a palindrome." &lt;&lt; endl; } } </code></pre> <p>This is my main body of code.</p> <pre><code>int main(){ int x = 1; string originalsentence; while (x == 1) { int a = 1; int input; string sentence; cout &lt;&lt; "Press 1 to reverse a string, 2 to check a palindrome, and anything else to quit: "; cin &gt;&gt; input; if(input == 1) { cout &lt;&lt; "Enter a sentence to reverse: "; cin.ignore(); getline(cin,originalsentence); originalsentence = sentence; cout &lt;&lt; string(sentence.rbegin(), sentence.rend()) &lt;&lt; endl; } if(input == 2) { cout &lt;&lt; "Enter a sentence to check: "; cin.ignore(); getline(cin,originalsentence); originalsentence = sentence; checkpalindrome(sentence); } cout &lt;&lt; "Hit 1 if you want to continue, anything else to quit: "; cin &gt;&gt; x; } } </code></pre> <p>So here is my problem. I am able to put in my choice about whether to reverse a string or check whether the string is a palindrome. However, when I try to reverse the string, it simply gives a blank line, then asks whether I want to continue. When I ask to check a palindrome, it simply says "is a palindrome" regardless of what I input. Any ideas?</p>
    singulars
    1. This table or related slice is empty.
    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.
    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