I have tried to start this program but I am so confused with dealing with strings. If any one could take a look and tell me if im on the right path it would be greatly appreciated. Heres the problem and what I have so far:

An organization wants to use encryption to protect classified information from eavesdroppers. The organization has developed an algorithm that encodes a string of characters into a series of integers between 0 and 94, inclusive. You have been asked to develop an application that decrypts this series of integers into its corresponding string of characters. The user should enter each integer of the encrypted message one at a time. After each integer is entered, the application should convert (that is, decrypt) the integer to its corresponding character, after which the application should display the string of characters that have already been decrypted. If the user enters a value that is less than zero or greater than 94, the application should terminate input.

2. Adding a global variable. Before main, add a definition for a string named message, which will hold the decrypted message. Initialize message to the empty string. Use one line for a comment.

3. Declaring a function prototype. After the variable you defined in Step 3, declare a function prototype for the decryptLetter function, which accepts an int parameter and does not return a value.

4. Defining a local variable, prompting the user for and storing the encrypted letter. Add code in main to define int variable named input, then prompt the user for and store the encrypted letter in that variable.

5. Testing the user input. Insert a while repetition statement that executes while the user input is in the range 0 to 94. This ensures that input terminates when the user enters a sentinel value.

6. Decrypting the input. Inside the while statement, call the decryptLetter function with input as its argument. This function, which you will define in Step 9, will decrypt the letter and append the character to string message.

7. Displaying output and prompting the user for the next input. Inside the while statement, add code to display the string message. Before the closing brace of the while statement, add code to prompt the user for and store the next encrypted letter.

8. Decrypting the input. After main, define the decryptLetter function, which accepts int parameter encryptedLetter. Letters should be decrypted by first adding 32 to the int. This value should then be converted to a char type. [ Note: You can implicitly convert an int to a char by assigning the value of an int to a char variable.] This calculation results in the number 1 decrypting to the character '!' and the number 33 decrypting to the character ' A'. To append the decrypted character to message, use the += operator. For example, message += ' A' appends the character ' A' to the end of message.

//Exercise 11.16: Decryption.cpp
// This application decrypts encrypted data one character at a time.
#include <iostream> // required to perform C++ stream I/O
#include <string>  // required for parameterized stream manipulators

using namespace std; // for accessing C++ Standard Library members

//string 
string message = () ;

//function prototype
 void decryptLetter (int);

// function main begins program execution
int main()
{
	int input; // user input

	//prompt for user input
	cout <<"\nEnter encrypted letter ( 0-94; -1 to exit): ";
	cin >> input;

	while ( input > 0 && input < 94)
	{
		 message = decryptLetter (input);
	
	}



   cout << "\n"; // insert newline for readability
   return 0; // indicate that program ended successfully

} // end function main

//define decryptLetterFunction
void decryptLetter (int)
{
	int encryptedLetter;

Recommended Answers

All 6 Replies

First, I'm not sure about this :

/string 
string message = () ;

Do this instead:

string message; //will hold the encoded message

Now your main problem is decryptLetter. This function is fairly simple.
What problem are you having with this exactly?

IM having a problem undertsanding what exactly to do inside the function. I know im gonna take the int input and add 32 but the converting of char type is where i get lost

Maybe this will help you :

char A = 'A';
int intValueOfA = A; //implicitly converted to int
char copyOfA = intValueOfA; //implicitly converted to int

ok i will give this a try thank you

Im still having trouble with this can any one help me out and show me an example of how this program can be done.

See if this helps:

void decryptLetter(char encryptedLetter){
 char decrypt = /* encryptLetter plus 32 */
 message = // message plus decrypet
 //done
}
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.