| sdelaney (1) | |
|
here is my code, the issue is its not determine if the value is a palindrome or not. // unit 5b.cpp : Defines the entry point for the console application. // // How to read a file // identify the string if its a palindrome or not // // Sheila DeLaney // Unit 5 // #include "stdafx.h" #include <iostream> #include <cctype> #include <fstream> #include <string> #include <cmath> #include <cstring> #include <iomanip> using std::cerr; using std::cout; using std::endl; using std::ifstream; using namespace std; int str = 0; int counter = 1; // count the number of loops up to 7 then stop bool isPalindrome(string str); int main() { bool isPalindrome=true; for (counter = 1; counter <= 7; counter++) { if (counter == 1) str = 10; else if(counter == 2) str = 34; else if(counter == 3) str = 222; else if(counter == 4) str = 111; else if(counter == 5) str = 67867876; else if(counter == 6) str = 444244; else if(counter == 7) str = 123454321; if(isPalindrome==true) {cout << isPalindrome; // tell me what the value is cout << endl; cout << str; cout << " is a palindrom" << endl;} else { cout << str; cout << " is not a palindrom" << endl;} system("Pause"); } return 0; } bool isPalindrome(string str) { int length = str.length(); //Step 1 for (int i = 0; i < (length - 1) / 2; i++) //Step 2 if (str[i] != str[length - 1 - i]) return false; return true; } | |
|
|
|
| Peter87 (3917) | |
|
You never call the isPalindrome function. There is also a problem with the function. You miss to check the character(s) in the middle of the string. | |
|
|
|