
please wait
#include <iostream> #include <string> using namespace std; string even(string str) { string o; string e; int d; int i = str.length(); //# of digits per string. if ((i % 2) == 0) { int d = i/2; e = str.substr(d,(d + 1)); } return e; //This is even. else { int d = i/2; o = str.substr (d); } return o; // This is odd. } int main() { string input; string x; string y; cout << "Please enter a number to see if its even or odd: "; cin >> input; cout << even(input) << endl; system ("pause"); return 0; } |
|
|
std::string get_center(const std::string & s ) { if ( s.length() == 0 ) return std::string() ; const bool length_is_even = s.length()%2 == 0 ; |