0

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.

0

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...

0

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 )

0

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

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.