Help Please! Urgent!

I have an assignment tomorrow and I just finished writing the code for it. However when I run the code and am going through the DECRYPT steps, it comes up with an error and i can't see how to fix it:(

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include <iostream>
#include <string>

using namespace std;

int main()
{
	const char k(5);
	string Encrypt_Input, Encrypt_Output, Decrypt_Input, Decrypt_Output;
	char Rerun_Selection;
	int Letter_Position, User_Selection;
	do{
		system("cls");
	do{
	cout << "************************************************************" << endl;
	cout << "*Welcome to the ENGR1200U Cryptographics Techniques Program*" << endl;
	cout << "*Please Enter Your Selection:                              *" << endl;
	cout << "*1. Decrypt                                                *" << endl; 
	cout << "*2. Encrypt                                                *" << endl;
	cout << "************************************************************" << endl;
	cin >> User_Selection;
	cin.ignore();
	} while(User_Selection!=1 && User_Selection!=2);
	
	if (User_Selection == 1)
	{
		system("cls");

		cout << "**********************************" << endl;
		cout << "*Welcome To The Decryption Lab!!!*" << endl;
		cout << "**********************************" << endl;
		cout << "Please Enter The Word That You Would Like Decrypted:" << endl << endl; //Uppercase Letters, No Spaces
		getline(cin,Decrypt_Input);
		{
			for (Letter_Position = 0; Letter_Position < Decrypt_Input.size(); ++Letter_Position);
				if (Decrypt_Input[Letter_Position] >= 65 && Decrypt_Input[Letter_Position] < 90)
					{
						Decrypt_Output += (Decrypt_Input[Letter_Position] - 'A' - k)%26 + 'A';
					}
				else if (Decrypt_Input[Letter_Position] >= 60 && Decrypt_Input[Letter_Position] < 70)
					{
						Decrypt_Output += Decrypt_Input[Letter_Position] - k + 26;
					}
				else
				{
					Decrypt_Output += Decrypt_Input[Letter_Position];
					Decrypt_Output="";
				}
		}

		cout << "The Word, Once Decrpyted Is: " << Decrypt_Output << endl << endl;

	}
	if(User_Selection == 2)
	{
		system("cls");
		cout << "**********************************" << endl;
		cout << "*Welcome To The Encryption Lab!!!*" << endl;	
		cout << "**********************************" << endl << endl;
		cout << "Please Enter the Phrase That You Wish to Encrypt:" << endl; //Uppercase Letters, No Spaces
		getline(cin,Encrypt_Input);
		{
			for (Letter_Position = 0; Letter_Position < Encrypt_Input.size(); ++Letter_Position)
			{
				if (Encrypt_Input[Letter_Position] >=65 && Encrypt_Input[Letter_Position] < 90)
				{
					Encrypt_Output += (Encrypt_Input[Letter_Position] - 'A' + k)%26 + 'A';
				}
				else
				{
					Encrypt_Output += Encrypt_Input[Letter_Position];
				}
			}
		}

		cout << endl << "The Phrase, Once Encrypted Is: " << endl << Encrypt_Output << endl << endl;
		Encrypt_Output="";
	}

	cout << "Would You Like To Rerun The Program? (Y/N):" << endl << endl;
	cin >> Rerun_Selection;
	}while(Rerun_Selection=='y' || Rerun_Selection=='Y');

		if (Rerun_Selection!='y' || Rerun_Selection!='Y')
		{
			cout << "Goodbye" << endl;
	system("pause");
	return 0;

		}
}
try changing the while condition of your first do while loop to this
 
while(User_Selection!=1 || User_Selection!=2);


change && to ||
If I do that then it just keeps in the loop
lezoudali wrote:
try changing the while condition of your first do while loop to this

while(User_Selection!=1 || User_Selection!=2);


That makes no sense. That condition can never be false.
@Chiron:

Telling us "there is an error" isn't very helpful. If this is really as urgent as you say, why would you withhold details that would help us fix your code quickly?
http://imgur.com/eKzaWvv

Thats the error that pop up
So it's triggering a debug assertion? That should make it pretty easy to debug. Use your debugger to find out which line the assert is triggering on, and what the state of the memory is at that point. That should give you some pretty good clues as to what's going wrong.
The first thing i see is return 0; is in a If condition. Why not simply put at the end of your code ?

If you say goodbye, why do you need system pause, or cls for that matter?

Because of this code
} while(User_Selection!=1 && User_Selection!=2);

If the user types X or x, the program goes into a endless loop.

You didn't give the user a way to exit.

Other than that, after I cleaned it up, I got no error. It doesn't work, but no errors that I can see.

Provide error with output example.
@MikeyBoy
Yeah...I'm new at this so this is what i got when i debugged it. and there's an arrow pointing to line 15. i have no idea what that means

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// throw -- terminate on thrown exception REPLACEABLE
#define _HAS_EXCEPTIONS 0
#include <cstdio>
#include <cstdlib>
#include <exception>
#include <crtdbg.h>

_STD_BEGIN

#ifdef _DEBUG
_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL _Debug_message(const wchar_t *message, const wchar_t *file, unsigned int line)
	{	// report error and die
        if(::_CrtDbgReportW(_CRT_ASSERT, file, line, NULL, message)==1)
        {
            ::_CrtDbgBreak();
        }
	}
_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL _Debug_message(const unsigned short *message, const unsigned short *file, unsigned int line)
	{	// report error and die
        _Debug_message((wchar_t *) message, (wchar_t *) file, line);
	}

#endif

_STD_END

/*
 * Copyright (c) 1992-2007 by P.J. Plauger.  ALL RIGHTS RESERVED.
 * Consult your license regarding permissions and restrictions.
 V5.03:0009 */
@ OP: Do you know what this error means? As in what it indicates? Because that is probably the first step in understanding this problem. The problem you're looking for is a small oversight, it's actually a pretty common beginner mistake. Yes, I have found it and I suspect that MikeyBoy has as well.

EDIT: Ask yourself why this only happens when you select the "Decrypt" option.
Last edited on
Line 35 for (Letter_Position = 0; Letter_Position < Decrypt_Input.size(); ++Letter_Position); remove the extra ';'



delete line 48 Decrypt_Output="";
Last edited on
@ Yanson: If you're just going to hand it to him then you might as well mention what else is wrong with that loop.

HINT: It's the same reason his encryption isn't working.
Last edited on
thank you @Yanson, but the error is still there

and my encryption works fine
@ OP: Really? Your program is only meant to encrypt the first letter of the string? That's more of an obfuscation wouldn't you say?

EDIT: Also, why are you isolating that particular for loop (yet not the inverse encryption section of it)? I agree that isn't impacting anything but it's weird to look at. It also suggests that you either didn't put them there on purpose or you put them there and you don't know why.
Last edited on
Have you run the program? it encrypts all of the letters
Yes, I have run the program and no, it does not encrypt all of the letters not as you have it posted above with the only change being the removal of the semicolon. For instance "Banana" changes into "Ganana". You posted this at 1:00 AM EST so is it possible you've made more changes and not updated it since then?
@OP: I am trying to help you here, but if you want me to go away I will. We can forget about the curly brackets at Lines 34 and 49, they aren't doing anything but at the same time they aren't doing anything.

If you're only trying to encrypt capitol letters then yes it works, but I don't see that mentioned anywhere.
lol look at the comments in the code beside the "please enter word...."
"Lol", the guy running the program can't see your comments.

I'll admit that I missed that because of the color I have Code::Blocks set to display comments with two slashes, but what you have here is not a good solution and you would be docked points on an assignment for that. Even if you wanted to be lazy about it, you could use "toupper()" to make the users input into all capitol letters. But why aren't you encrypting lower case letters anyway?
Topic archived. No new replies allowed.