also how can i make it not print out letters, i thought this would work. but its not

while (integer != alpha)

it does not work.

ok i am having more problems. when u run the code with a number like 1234567890 it prints out 987654321 and that is fine. but if you enter something like 123456789123456789 it prints out something else.

That would be attributed to overflow i.e. trying to store a number in an integer variable which exceeds the capacity of an integer data type.

My output:

Please input an integer: 23434324234343
original string: 23434324234343
reversed string: 34343242343432
reversed integer: 4007032 // overflow

also how can i make it not print out letters, i thought this would work. but its not

while (integer != alpha)

it does not work.

It would be :

if ( isalpha ( integer [cntr] ) || ispunct ( integer [cntr] )  )
{
    --cntr ;
}

Though there are better ways of doing the same thing in C++ using its inbuilt string functions...

is there a way to change the overflow

is there a way to change the overflow

One method is to avoid the integer conversion, and simply use a boolean to keep track of whether we've hit a nonzero number yet. As long as that's false, you keep ignoring the 0s.

Or you could just use a larger integer... (e.g. long int )

ok i will try tha ttomorrow. Thank yall

ok this works to a point. when i enter 123d123 it prints out the last the numbers in reverse like this 321, but i need it to print out 321321, and skip over the d. how can i do this.

[LIST=1]<LI class=li1>[B]if[/B] [B]([/B] isalpha [B]([/B] integer [B][[/B]cntr[B]][/B] [B])[/B] || ispunct [B]([/B] integer [B][[/B]cntr[B]][/B] [B])[/B]  [B])[/B]
<LI class=li1>[B]{[/B]
<LI class=li1>    --cntr ;
[*][B]}[/B]

[/LIST]but when i enter

It works fine in my case, what part are you having problems with ? The isalpha successfully skips the alphabetic characters.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.