Sunday, August 2, 2009

*************** programming C++****************?

i have an assignment for this week which is Write a program that reads in a five-digit integer and determines whether it is a palindrome. the instructor wants us to check to make sure that the user inputs a 5 digit number. It means that if user enter a character or press enter instead of a 5 digit number, the user should get a prompt that says "please enter a number."


is there any code for this in C++. i already tried the .length() but seems like this code is for the character and strings.


can anyone help me with that please? :)

*************** programming C++****************?
I have nothing to add on the other guy but I'll explain a little if ((x / 10000) %26gt; 0 %26amp;%26amp; (x / 10000 )%26lt; 10) verify that it's a 5 digits number you can replace it with ((x%26lt;100000)%26amp;%26amp;(x%26gt;9999)) but I advise you to make the input a string because later when you check if it's a palindrome it will be easier with a string


I hope you understand
Reply:unsigned int x = 0;


bool a = false;


do


{


cin "Enter a 5 Digt Number: " %26gt;%26gt; x;


if ((x / 10000) %26gt; 0 %26amp;%26amp; (x / 10000 )%26lt; 10)


{


then a = true;


else cout %26lt;%26lt; "Invalid Number!";


}


}while(a == false);


No comments:

Post a Comment