-
Invalid input?
Hello! Yes this is for homework, but I only have a few teeny questions. Why, when I compile my program, does it give me three errors about end1 not being in iostream?? I know it is end(one) and not end(lowercase l).
But it still should work, right?
Also, how can I add a check to make sure the input is an integer and not, say, a letter?
Thanks for your help.
Code:
//Palidrome 2.29
#include <iostream>
int main()
{
using std::cout;
using std::cin;
using std::end1;
int integer; //user input
int digitOne, digitTwo, digitThree, digitFour, digitFive; //breaks up input
cout << "Enter a five-digit integer: "; //prompts user
cin >> integer; //place-holder for input
digitOne = integer / 10000;
digitTwo = integer % 10000 / 1000;
digitFour = integer % 10000 % 1000 % 100 / 10;
digitFive = integer % 10000 % 1000 % 10;
if (digitOne == digitFive && digitTwo == digitFour)
cout << integer << " is a palindrome." << end1;
else
cout << integer << " is not a palindrome." << end1;
return 0;
}
-
it is endl not a 1 but a l.
yes I thought it was a 1 too but I found out it was endl.
If that is unclear still (it would be to me) it is a lower case L.
I am sure it is lower case L. I used it before...
Edit: Yes it is lower case L. I just tried it and it worked for me.
-
Thanks for your reply. The guy who was tutoring me told me that I was wrong when I had endl; in my pseudocode. I guess I should not listen to him next time and find a new tutor.
Do you know of any way I can check for invalid input?
-
LOL Your welcome. Or listen but maybe not do or check first. LOL
Edit: YES! I helped someone! :) :) :) :)
-
Do you know how to check for invalid input? I tried to make another while loop but it wouldn't run properly
-
Code:
cin >> integer;
if( integer != (/* logical conditions for valid input */) return 0;
digitOne = integer / 10000;