Confusion on Palindrome homework

Yeah, worlds worst programmer back for more fun and excitement. I have a question on the palindrome. Actually two.

the first one is my math logic for determining the palindrome accurate as far as variables and comparing is concerned?

The other is that my program isn't printing out the n variable that I entered. Any help would of course be appreciated.

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
64
65
66
67
68
69
70
71
72
73
74
  // Lab 2, Creating a Palindrome
// Programmer: 
// Editor(s) used: XP Notepad
// Compiler(s) used: VC++ 2010 Express

// preprocessor directive for streaming, variable, and ending statement.
#include <iostream>
using std::cin;
using std::cout;
using std::ios;
using std::endl;

// preprocessor directive for string, and variable string.
#include <string>
using std::string;
using std::getline;

#include <cstdlib>

int main() {

//Jesse Burns program number 2: creating palindrome.
cout << "Lab 2, creating a Palindrome" <<endl;
cout << "Programmer:" <<endl;
cout << "Editor(s) used: XP Notepad" <<endl;
cout << "Compiler(s) used: VC++ 2010 Express" <<endl;

//Create a while loop so the information can loop back and return
while(true)

{

//The variables needed to input and compare information.
int a;
int b;
int n;
string buf;

//Entering the information.
cout << "Enter a five digit number to determine a palindrome or press q to quit."<<endl;
cin >> buf; n = atoi(buf.c_str());
cin.ignore(1000,10);


//The needed if statement for the loop to quit.  Inluded the break statement as well.
if(buf == "Q" || buf == "q")break;
{

//The math to compare the opposite ends.
a = n % 10;
b = n / 1000;

//Actually comparing the opposite numbers.
if (a == b)continue;

//The math needed to compare the inner numbers
a = n % 10;
b = n / 100;

//The if statement for the inner numbers
if (a == b)
{
cout << "The palindrome you enter is "<< n <<"."<<endl;

}


}
}
 cout << "Press enter to continue..."<<endl;
 cin.get();


}


Topic archived. No new replies allowed.