Caesar Cipher program finished, but need help with bugs.

Pages: 12
@whitenite1

Actually it does work somehow in respect to your concern.

Our issue now is spacing. When the text file holds

<25CNM'S OZX ZMX ZSSDMSHNM SN SGD LZM ADGHMC SGD BTQSZHM.#

>7IETR BM LTF. HY TEE MAX ZBG CHBGML BG TEE MAX IETVXL BG TEE
MAX PHKEW, LAX ATW MH PTED >14UZFA YUZQ. IQ'XX MXIMKE TMHQ BMDUE.
>23URXQG XS WKH XVXDO VXVSHFWV.#

It should print out

DON'T PAY ANY ATTENTION TO THE MAN BEHIND THE CURTAIN.


PLAY IT SAM. OF ALL THE GIN JOINTS IN ALL THE PLACES IN ALL
THE WORLD, SHE HAD TO WALK INTO MINE. WE'LL ALWAYS HAVE PARIS.
ROUND UP THE USUAL SUSPECTS.

However it shows

Enter filename: test1.txt
DON'T PAY ANY ATTENTION TO THE MAN BEHIND THE CURTAIN.

__PLAY IT SAM. OF ALL THE GIN JOINTS IN ALL THE PLACES IN ALL THE WORLD, SHE HAD
_TO WALK INTO MINE. WE'LL ALWAYS HAVE PARIS. ROUND UP THE USUAL SUSPECTS.

It has 2 spaces on top and 1 on the bottom. While I work on that, if anyone noticies why can you just give me a rough idea of what area of code to take a look at? My bet is some where around the isspace() or the #, since those are the only things that output spaces.
Last edited on
I got it... isspace counts newlines I guess
@Yezman

Congratulations. I, too was working on your program, and mine works as well. ( I'm doing it for fun. I am not in school. I'm already retired) I don't understand why the two digits work, but I see they do. I used the <25 instead of a >1 for the text, and I still get the correct output. I had a problem for awhile with the lettering going above 'Z' or below 'A', but I found a simple fix. Here's how I did it.
1
2
3
4
5
6
7
8
9
10
if (c >='A' && c<='Z')
		{
			c+=shiftvalue;
			if (c >='\x5A')  //Hex for 'Z'
				c -= 26;
			if (c <'\x41') // Hex for 'A'
				c+=26;
			char ch = c;
			cout << ch;
		}


How did you program it?
Well I just submitted it to the grader and got 20/50. So my code has a lot of bugs I have to find. The autograder just runs a bunch of tests @ 2 pts each to check everything.


*******************************************
***** *****
***** Your output is: *****
***** *****
*******************************************
Enter filename:
GIVE SK THE XOTM! MY VXKIOUAY!




*******************************************
***** *****
***** Correct Output *****
***** *****
*******************************************
GIVE ME THE RING! MY PRECIOUS!

Every other word is off by 6. So i am guessing the shift changes for each word. I think it has to do something with my code to keep the characters between A and Z. Or, something to do with a + or - change in the input.

Might have issues with stuff like.

<-2 means shift downwards by -2 (same as shifting upward by 2)
>-25 means shift upwards by -25 (same as shifting downward by 25)
+-3 means add -3 to the current shift value.

I am going to try to fix that then call it a night. I'll keep this updated as I move along. I just posted my current code in the OP.

----

I am not one to be correcting anyone at all, but I think yours only works if the shift is less than 26. Like if the shift was 60, would yours work? I used % in mine.
----------

I just got 2 different answers. When the file is >2c it returns I but when it is >2A, it cout's C. So that is an issue.
Last edited on
Ok. So like I said about they are off by 6. >2c gives me I and it SHOULD give me C. But, I is 6 away from C. So I think I might be on to something, but I am basically guessing and checking. If anyone can figure out why this happens, can you point me in that direction?

**Note that the program is supposed to convert characters to upper first.
Last edited on
*Shameless bump*.... Still can't figure out the issue with >2c giving me I when i should get C. Taking another look at it now.
Last edited on
Ok I got that issue, but I have been stuck on this problem all day.

*******************************************
***** *****
***** Your output is: *****
***** *****
*******************************************
Enter filename:
ROSEBUD 1940. abc3210.


*******************************************
***** *****
***** Correct Output *****
***** *****
*******************************************
ROSEBUD 1940.GHI3210.

So our issue again is with the lower to upper conversion. And also that extra space. We have looked over both the spacing and toupperByReference for some time now and can't seem to pinpoint the issue. It could also have to do with shifts we think, and something not resetting. Could you lead us in the right direction for starting to fix these issues. It does fine with all the examples listed in the spec and the textfile given in the assignments page.
Topic archived. No new replies allowed.
Pages: 12