Problem with palidrome

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?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
  // 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.
What's wrong with it?
It works for me (if I enter each digit on a separate line).
You could enter it into a string so that you get one number, then dissect it, but that's slightly more complex. Or you can do something like this.
 
cin >> a;
Topic archived. No new replies allowed.