Hey guys I have a program that I need to write and I have no idea how to do it:
this program has to prompt the user in a menu to encrypt a message, decrypt or quit.
I'm supposed to use functions in this program
This is what i am supposed to use without removing any parts, just adding things where needed.
#include%26lt;iostream%26gt;
using namespace std;
int menu();
void encrypt(int);
void decrypt();
int main(){
int choice;
int shift = 7; // default shift
choice = menu();
while (choice != 3){
if (choice == 1){
cout %26lt;%26lt; "Enter the 'shift' value: ";
cin %26gt;%26gt; shift;
encrypt(shift); }
else
decrypt();
cout%26lt;%26lt;endl%26lt;%26lt;endl%26lt;%26lt;endl;
choice = menu();
}
return 0;
}
I don't even know how to get started functions kind of confuse me
Can someone at least point me in the right direction?
Need help with a C++ program?
You will need to write two functions. I'm not really sure what the shift is, but to get started, do this:
void encrypt(int shift)
{
//Use code in here to translate the value. I'm guessing the shift
//value, since it is an integer will return a letter, so therefore
//use a switch to print out the letter:
switch (shift)
{
case 1:
cout %26lt;%26lt; "k ";
break;
case 2:
cout %26lt;%26lt; "n ";
break;
//... and so on for each value
}//End Switch
}//End Encrypt
//The decrypt is going to need to take in a string, and return
//numbers that correspond to that string.
void decrypt()
{
string sIn="";
//Get a value for this string
cout%26lt;%26lt;"Enter the string to be decrypted:";
cin%26gt;%26gt;sIn;
//Get a number value for each letter:
for (int x=0; x %26lt; sIn.length(); x++)
{
//Get the next letter in order
string sTemp = sIn.substr(x,1);
//Convert this letter to a number and output that number
switch (sTemp)
{
case "k":
cout %26lt;%26lt; "1 ";
break;
case "n":
cout %26lt;%26lt; "2 ";
break;
//...and so on
}//End Switch
}//End For loop
}//End decrypt
That should get you started. Good luck!!
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment