Hey there,
So I've looked everywhere for help with my assignment until finally I found this useful service. I'm a C++ beginner and so far the problem solving and coding have fulfilled all expectations. If there is anyone to offer suggestions for my assignment, that'd be amazing!
What it is is a C++ program identifying valid palindromes of 50 characters maximum. My professor wants us to read in a string or array from the user, containing letters and/or numbers but none of the other printable characters. Also, if the user enters more than one word separated by spaces, the spaces, along with non acceptable characters, must be removed from the string/array and copied into a parralel array or string.
I've started working but haven't made much progress. My approach to the problem has been to read the user's input from function main(), validate the input of 50 characters (while loop), promote characters to uppercase and copy the input into another string/array. I then plan on passing the string/array as arguments to another funtion (bool) to test the validity of the palindrome.
If there's anyone willing to tackle this problem; all help will be greatly appreciated!
Here's what I have so far:
#include <iostream>
#include <string>
#include <cstring>
#include <cctype>
using namespace std;
//Prototype
bool validPal(string, int); //Test for palindrome
int main()
{
string phrase, phrase2; //To hold string entered by user & duplicate string
int length; //Holds length of string characters
cout << "\t\t\tIS IT A PALINDROME?\n";
cout << "\t\t\t___________________\n";
cout << "\n\nEnter a sentence, phrase or word no longer than\n50 characters"
<< " to determine if it is a Palindrome:\n\n";
getline(cin, phrase); //Input from user to be tested
//Validate input to 50 characters maximum
while (phrase.length() > 50)
{
cout << "\nYou have entered too many characters. Please try again:\n\n";
getline(cin, phrase);
}
//Assign length of the string to 'length'
length = phrase.length();
//Loop copies original string into a 2nd string
for (int i = 0; i == phrase.length(); i++)
{
if (isalpha(phrase[i])) //Test characters for letters
phrase2[i] = toupper(phrase[i]); //Promote letters to uppercase
}
//Displays the 2nd string
for (int j = 0; j < phrase.length(); j++)
{
cout << phrase2[j];
}
cout << endl;
return 0;
}
//validPal returns true/false for palindrome testing
bool validPal(string PHRASE, int LENGTH)
{
}