Ok, worlds worst programmer here. I must admit, this isn't nearly as confusing as figuring out the confusing logic of the hollow printed square using loops, but it's still confusing. Here is the code I've written below.
// 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;
int main()
{
//Jesse Burns program number 1: the basics.
cout << "Lab 1, Programming Basics" <<endl;
cout << "Programmer: Jesse Burns" <<endl;
cout << "Editor(s) used: XP Notepad" <<endl;
cout << "Compiler(s) used: VC++ 2010 Express" <<endl;
int num1 = 0;
int num2 = 0;
int num3;
string buf;
cout << "Enter a number to determine a palindrome or Q to quit:"<<endl;
cin >> buf; num3 = atoi(buf.c_str());
cin.ignore(1000,10);
while(true)
{
if (buf == "Q" || buf == "q")break;
cout <<"Enter a number."<<endl;
}
num1 = num3 % 10;
num2 = num3 / 1000;
if(num1 == num2)
num1 = num3 % 10;
num2 = num3 / 100;
if(num1 == num2)
cout <<" The palindrome is "<< num1 << num2 << num3 << num2 << num1<<endl;
cout << "Press enter to continue..."<<endl;
cin.get();
}
Ok, so the logic isn't that bad, and I think I'm onto something as far as the pattern is concerned. The only thing I'm worried about is that I can't use the if/else statement without using an actual printed statement.
Now the only thing I don't like about that, is that I don't need that printed statement! So using a while(true) loop to break at Q to end the loop, it keeps on looping. Is there any suggestions or advice on this one?
I'm trying to create a five number palindrome btw, with it ending at a sentinel q. Thanks.
No need to convert the number to an actual number before checking if it is a palindrome. Only check that the syntax of the input is in the format of an actual number. i.e. no leading 0's and no non-digit characters in the string
Also you have just created an inifintely running loop on line 32