Keeping each input in a while loop instead of just the last one

The code you'll see is a palindrome checker. Every function works, and it will successfully compare a string to determine if it is one or not, and it outputs the appropriate message.

However, it's only set to handle one input at a time. I'm trying to figure out how to create a while loop that will pass each string looped through all the functions and cout the appropriate message for each one.

I know it would look something like
while (x != end)
getline etc

but that only stores and checks 'end' since it will be the last thing entered.

How can I pass all of the looped inputs through my functions?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
  #include <iostream>
#include <stdio.h>
#include <ctype.h>
#include <locale.h>
#include <limits.h>
#include <string>
#include <algorithm>
#include <bits/stdc++.h> 
using namespace std;


string Pal(string sent)
{
	for (int i = 0; sent[i]; i++)
		sent[i] = tolower(sent[i]);
	
	return sent;
}


string Reverse (string rev)
{ 
    string str = rev; 
    reverse(str.begin(), str.end());    
    return str; 
} 


string Filter (string clean)
{
    
  
    for (int i = 0, len = clean.size(); i < len; i++) 
    { 
        // check whether parsing character is punctuation or not 
        if (ispunct(clean[i])) 
        { 
            clean.erase(i--, 1); 
            len = clean.size(); 
        } 
    } 
     
    clean.erase(remove(clean.begin(), clean.end(), ' '), clean.end());

    return clean;
    
}

int main ()
{
    string x;
    string p;
    string xx;
    
    getline(cin, x);
    p = x;
    xx=x;
    x = Pal(x); 
    x = Reverse(x);
    x = Filter(x);
    p = Pal(p);
    p = Filter(p);
 
    if (  p == x  ) 
    {
        cout << xx << " is a palindrome." << endl;
    }
    
    else 
    {
        cout << xx<< "is NOT a palindrome." << endl;
    }
    
}


This was homework, but only the part I've already coded about checking one palindrome. This extra is just personal learning.
Enclose this part of the code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
    getline(cin, x);
    p = x;
    xx=x;
    x = Pal(x); 
    x = Reverse(x);
    x = Filter(x);
    p = Pal(p);
    p = Filter(p);
 
    if (  p == x  ) 
    {
        cout << xx << " is a palindrome." << endl;
    }
    
    else 
    {
        cout << xx<< "is NOT a palindrome." << endl;
    }


Within a while loop. The while loop could either iterate the number of times the user wants to give input or until a the input string is given a specific value (eg. x = "exit")


From what I have understood you want the user to be able to keep checking for palindromes more than once. If you want the user to be able to input more than one string at a time and get all outputs at the same time then you need to use a vector.
Hello jjordan33,

This was my first thought:
1
2
3
4
5
6
7
8
9
char choice = 'Y';

while (std::toupper(choice) == 'Y')
{
 	// your code here.

	std::cout << "\n Prompt to continue: ";
	std::cin >> choice;
}


For your header files:

"#include <bits/stdc++.h> " is not a standard C++ header file. Also it will include all the C++ versions of the header files you just included. It is best not to use this header file.

"stdio.h" is covered by "iostream" and is not needed mostly because you have no C code that needs it.

"ctype.h" should be "cctype".

"local.h" should be "local". Although I do not believe there is anything in your code that needs this file.

"limit.h" should be "limits". Again I do not believe there is anything in your code that needs this file.

Hope that helps,

Andy
@Andy he said "Every function works perfectly". So maybe the headerfiles mentioned by him are the right names for his compiler.. (^_^'')
Topic archived. No new replies allowed.