Need help

Hello Everyone,
I am in need in help with a palindrome program. Below is what I have, but keeps crashing and I am not sure why. Yes, I am a newbie to programming and C++.

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
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <string>


using namespace std;

//Starting point. This program will ask the user to input a word, and the program will reply if it is a palindrome until END is typed to terminate.

int main()
{
	string word972;
	bool end;
	

//Asking user to input a word.
	do{
		
		cout << "Please enter a word to find out if it is a palindrome or type END to terminate." << endl;
		cout << endl;
		cin>>  word972;


//Break function for "END".
	while (word972.length()) 
	(word972 != "END");
	if (!"END") { break; }
		
		
  if (word972 [0] == 'E' && word972 [1] =='N' && word972 [2] == 'D' && word972 [3] == '\0') 
	
	  end = true; 

else 

	end = false;
	int length = (word972.length());


// Bool and for loop for word input, also to display word as it is typed.
bool palindrome=true;

	for (int i=0; i<length; i++)

	{

	if(toupper(word972[i])!=toupper(word972[length-i-1]))

	if(word972[i]!=word972[length-1-i]) 
palindrome=false;

	}

// Output of palindrome respone.
	if (palindrome) 
	
	{
	
		cout << word972 << " is a palindrome" << endl;
	}
	
	else 
	
	{
	
		cout << word972 << " is not a palindrome" << endl;
		
	}

// Whlie loop until END is typed to terminate.
	}

	while (word972!="END");
	
	{

	cout << endl << "This is the end"<<endl; 

	}

	system ("PAUSE");
return(0);
}
Last edited on
There is many syntax errors in this and I think you are trying to create functions the wrong way.

Have you taken any C++ classes or read any books?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
using namespace std;

int main()
{
char word[10];
for ( int x = 0; x < 10; x++ ) { word[x] = ' '; } //initialize array to nothing

cin >> word;

char palindrome[10];

for ( int x = 0; x < 10; x++ ) { palindrome[x] = word[x]; } // copy to palindrome

int count = 9;

for ( int x = 0; x < 10; x ++ ) { if ( word[x] != palindrome[count] ) { cout << "Not a palindrome";}
else { count --; }
}
if ( count == 0 ) {cout << "Is a palindrome";}


return 0;
}


This is a VERY SHITTY example to get you thinking about the logic.
Last edited on
I tried doing that, but did not work.
@MaxDaniels

Look at some of my other posts as to why you shouldn't have line 2, and what to do about it. Then realise you are using std::count

http://www.cplusplus.com/reference/algorithm/count/
@dan2n1

So you are implying you don't want any more help?

Edit:

Also, don't start new topics on the same subject, just keep the original one going.

Did you apply the advice given in the other topic?
Last edited on
Topic archived. No new replies allowed.