My program needs to print the mirror image of a letter that's input. All the letters will be input in uppercase. And the mirror image will be printed in uppercase.

So if I input A it's mirror image would be Z
if B, then Y
if C then X
if M then N.

My problem is coming up with an algorithm with the problem itself. I guess I could do several if statements or use switch, but I think that would be frowned upon. know there's 26 letters in the alphabet. I also know that the difference between the input and the mirror of all letters is odd and decreases by 2 from A to M ( or Z to N ) .

Any ideas?

i would suggest looking at the ascii code for the character. To start with the ascii code for 'A' is 65 and for 'Z' is 90, there rest lie inbetween unsuprisingly. You first step would be to determine ig it is on the right or left hand side. So is it <= 77 or >=78 once you have this then you can carry on.

Once you have done that then you can go about subracting, and adding values to and from the numbers 65 and 90. I'm not going to go into too much detail ill leave you with something to think about.

If you get stuck with it then we can provide more help. But that should be more than enough help for now

Chris

Yet another tip: you can get "mirrored" char with only one and a very simple expression without any explicit numbers...

Here's what I came up with for the left hand side...

Take the difference between 90 and upper bound for the LHS ( 90 - 77 ), add the lower bound for the LHS ( 65 ), and finally add the difference of the upper bound and the input
( 77 - 65 )

So for LHS it would look like

( ( 78) + ( 77 - Input ) )

I guess it works, but it seems sorta sloppy. Any suggestions?

By the way Ark I'm not ignoring you, I'm just so much a novice at this that I can't make any use of what you gave me.

Yet another tip: you can get "mirrored" char with only one and a very simple expression without any explicit numbers...

Now thats a new one to me, normally i can thing of these thing straight off the top of my head. But not this one lol otherwise i would of suggested it. I spend quite a bit of time finding quickest ways to do things but this one got me :P

Okay so I'm doing

90 + 65 - Input

Okay so I'm doing

90 + 65 - Input

Now, to make it more portable, and to eliminate the "magic numbers" do the arithmetic using the actual characters.

Clever little problem. I like it. I may torture my own students with this sometime. :twisted:

Now, to make it more portable, and to eliminate the "magic numbers" do the arithmetic using the actual characters.

Clever little problem. I like it. I may torture my own students with this sometime. :twisted:

That was how i inteded to do it, doing the arithmetic with the actual characters, i just went along the line of explaining numbers so he knew where i was coming from :P

Yer it would make a nice little problem for quite a few classes i imagine, i can't wait till i start computer science and get to have a ready source of problems :twisted:

Chris

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.