...

View Full Version : Resolved C++ keep keeping 4 digits



primefalcon
11-12-2008, 12:01 AM
Hi there I'm trying to put together a program that can test to see if a number is the same forwards and backwards in a 4 digit number....

and I'm coming across one little hiccup how do you keep 0's in a number before a non-zero number for example

stop it from turning 0001 into just 1 in a variable

Is there a way to do this?

primefalcon
11-12-2008, 01:27 AM
Nvm I worked out another way to do it here's the source for anyone who's interested


#include <iostream>
using namespace std;

int main()
{

cout << "\n\n\n";

int a = 0;
int b = 0;
int c = 0;
int d = 0;
int count = 0;
while(a <= 9)
{
while(b <= 9)
{
while(c <= 9)
{
while(d <= 9)
{

if (a == d && b == c)
{
count++;
cout << count << "->" << a << b << c << d << "\n";
}

d++;
}
d = 0;
c++;
}
c = 0;
b++;
}
b = 0;
a++;
}

cout << "\n\n\n";
return 0;
}

jmac555
11-12-2008, 06:57 AM
good peice of code, however there is a simpler way to achieve what you want

include <math.h> and that gives you access to the
isPallendrome
which should do what you want

primefalcon
11-12-2008, 10:21 PM
still though the problem I had was keeping like 3 0's in say 0001 without the way I did it, c++ kept stripping the 0's from the variable, and I wasn't sure how to overcome that



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum