This is actually quite a simple program that I am perplexed as to why it doesn't work. It's basically the creation of a five digit palindrome. Each number has to match the inner or outer. I thought this would be simple, but it's not working for me. Any pointers?
// Lab 2b, Palindrome
// Programmer: Jesse Burns
// Editor(s) used: JNotePad
// Compiler(s) used: VC++ 2010 Express
// The necessary C++ file library
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
using std::ios;
#include <string>
using std::string;
#include <cstdlib>
int main()
{
// Jesse Burns, Lab 2a.
cout << "Lab 2b, Palindrome\n";
cout << "Programmer: Jesse Burns\n";
cout << "Editor(s) used: JNotePad\n";
cout << "Compiler(s) used: VC++ 2010 Express\n";
cout << "File: " << __FILE__ << endl;
cout << "Compiled: " << __DATE__ << " at " << __TIME__ << endl << endl;
// Variables for Palindrome
int a;
int b;
int c;
int d;
int e;
string buf;
//Enter the size of the square you would like
cout << "Enter the numbers you want to determine if it is a palindrome. "<<endl;
cin >> buf; a = atoi(buf.c_str());
cin.ignore(1000, 10);
cin >> buf; b = atoi(buf.c_str());
cin.ignore(1000, 10);
cin >> buf; c = atoi(buf.c_str());
cin.ignore(1000, 10);
cin >> buf; d = atoi(buf.c_str());
cin.ignore(1000, 10);
cin >> buf; e = atoi(buf.c_str());
cin.ignore(1000, 10);
if (a == e && b == d)
{
cout << a << b << c << d << e << "is a palidrome!"<<endl;
}
else
{
cout << "Is not a palindrome. Enter another number."<<endl;
}
}
I would first suggest that you input directly into the variables. I don't really see the point to going out of your way to turn an integer input into a string, then back into integer input.