Palindrome Program HELP!

I have a program where it will ask the user for a word and check if it's a palindrome.


The problem I have is:

1) I need to modify the program so that it will take sentences rather than a single word

2) The program does not terminate correctly, it will keep on asking for another word instead of executing with the final statement "The End"

3) I need to modify the program so that it will only take capital letters, removing anything that is not A through Z
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
//Alexandros Panayi
//CS 003A
//Palindrome Assignment
//Done with Visual Studio 2013
//#include <QtCore/QCoreApplication>
#include <iostream>
#include <cstdlib>
#include <string>

using namespace std;

void makeUpper(char *word);
void getInput(char *title, char word[]);
void getReverse(char word1[], char word2[]);
char* find(char* start, char what);
bool palindrome(char *word1, char *word2);

int main()
{
	//QCoreApplication a(argc, argv);
	char word1[30], word2[30];
	bool again = true;
	while (again)
	{
		getInput("Please enter a word: ", word1);
		if (*word1 == '\0')
			again = false;
		else
		{
			makeUpper(word1);
			getReverse(word1, word2);
			if (palindrome(word1, word2))
				cout << "you have a palindrome!" << endl;
			else
				cout << "You do not have a palindrome!" << endl;
		}
	}
	cout << "The end!" << endl;
	system("PAUSE");
	return 0;
}

void getInput(char *title, char word[30])
{
	cout << title;
	cin >> word;
}

void makeUpper(char *word)
{
	while (*word != '\0')
	{
		if (*word >= 'a' && *word <= 'z')
			*word -= 32;
		// *word = *word - 32
		word++;
	}
}

void getReverse(char word1[], char word2[])
{
	char *end = find(word1, '\0');
	end--;
	while (end != word1)
	{
		*word2 = *end;
		word2++;
		end--;
	}
	*word2 = *word1;
	word2++;
	*word2 = '\0';
}


char* find(char* start, char what)
{
	while (*start != what && *start != '\0')
		start++;
	return *start == what ? start : NULL;
	/*
	if(*start == what)
	return start;
	else
	return NULL;
	*/
}


bool palindrome(char *word1, char *word2)
{
	bool same = true;
	while (*word1 != '\0')
	if (*word1 != *word2)
	{
		same = false;
		break;
	}
	else
	{
		word1++;
		word2++;
	}
	return same;
}
1) I need to modify the program so that it will take sentences rather than a single word
Use std::getline.

2) The program does not terminate correctly, it will keep on asking for another word instead of executing with the final statement "The End"
Related to first. Stram extraction cannot give you an empty string, they will read at least one non-whitespace character.

3) I need to modify the program so that it will only take capital letters, removing anything that is not A through Z
It is better to modify inputted string replacing all letters with coresponding capitals.
Topic archived. No new replies allowed.