1

I was viewing the practice problem section and decided to give a go at them, anyways, this is my Palindrome dector code. Could someone just take a look at it and explain to me if there is a better way to execute this problem?

- michael

// Palindrome check by Michael Turbe (c) 2009

#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

int main(void)
{
	// system config
	system("TITLE Palindrome");

	// variables
	string User_Input;
	string Input_Reverse;

	string::iterator Position;

	bool StartOver;

	// loop allows multiple takes on program without restart
	do
	{
		StartOver = false;
		system("CLS");

		cout << "Palindrome Check" << endl;
		cout << "----------------" << endl << endl;
		cout << "Enter a word or series of numbers." << endl << endl;

		cin >> User_Input;

		string Input_Reverse(User_Input.begin(), User_Input.end());

		reverse(Input_Reverse.begin(), Input_Reverse.end());

		if(User_Input == Input_Reverse)
		{
			cout << endl << User_Input << " is a Palindrome." << endl << endl;
		}
		else
		{
			cout << endl << User_Input << " and " << Input_Reverse << " are not the same." << endl << endl;
		}
		
		cout << "Would you like to start over? 1 - Yes, 0 - No" << endl;
		cout << "Enter choice and press ENTER." << endl;
		cin >> StartOver;
	}
	
	while(StartOver == true);

}
Votes + Comments
Congrats on using code tags on your first post, very few manage it.
2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by xtremerocker
0

Your answer seems fine to me.

There are many different ways of solving the problem, but whether any of them are "better" would be a subjective statement IMO.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.