Hey guys, im slowly learning the basics and i thought id make some sort of a program that converts a string to ascii then screws with the numbers and kind of "encodes" the string. My only problem is the decoding section of it. Im not trying to do anything serious cause i know youd alll laugh at me when you read the code, im just writing simple little programs so i can learn from trial and error, but im quite stumped now. Any help would be greatly appreciated thanks.
once again thanks for any help in advance that you can offer meCode:#include <iostream> #include <string> using namespace std; int main() { int choice; cout<<"ENCRPTER PROGRAM"<<endl<<"Please choose which function you want to perform"<<endl; cout<<"1. Encrypt a message"<<endl<<"2. Decrypt a message"<<endl; cin>>choice; cin.ignore(); if (choice==1) { char phrase[201]; float codephrase[201]; cout<<"Enter a phrase to be encoded: "<<endl; cin.getline(phrase,201,'\n'); for (int x=0;x<201;x++) { codephrase[x] = (int)phrase[x]; } cout<<"Succesful Encode"; cin.get(); // cout<<"The sentence in ASCII: "<<endl; // for (int i=0;i<201;i++) // { // if (codephrase[i]==0 ) // { // break; // } // cout<<codephrase[i]<<" "; // } // cout<<endl; cout<<"The sentence encoded: "<<endl; for (int y=0;y<201;y++) { if (codephrase[y]==0) { break; } cout<<codephrase[y]/2*3/2*3/2*3<<" "; } } // This is the section i need a bit of help with else if (choice==2) { char phrase[201]; float codephrase[201]; float decodephrase[201]; cout<<"Enter a phrase to be decoded: "<<endl; cin>>codephrase[201]; cin.ignore(); for (int x=0;x<201;x++) { decodephrase[x] = codephrase[x]/3*2/3*2/3*2; } for (int o=0;o<201;o++) { phrase[o] = (char)decodephrase[o]; } cout<<"Succesful Decode"; cin.get(); cout<<"The sentence decoded: "<<endl; for (int y=0;y<201;y++) { // if (codephrase[y]==0) // { // break; // } cout<<phrase[y]<<" "; } } else { cout<<"That isnt an option"; } cin.get(); }
~lac