Basically i need to encrypt a message into ascii values & i also need to allow the user type some ascii values thus decrypting the values into characters that are placed within the code. I'm still a beginner so maybe some help with this code would do. Thank you.
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
usingnamespace std;
#define Q 2000
void main(){
char array1[Q]={"A gentle, dull flickering flame, burns in the marble hearth. Its dim light scarcely illuminates the small, cozy room with its quiet elegance. The dismal light plays softly causing shadows over the solitary figure of a wooden desk at which Allen was roaming through his memories. Thinking back in the past where he once had a friendship which was out righteously incredible. She was the girl of his dreams, in a way which she had everything he had ever sought out in a beautiful and clever girl. Most of all she had his heart. Her style was incredible in the way the outfits she would wear would match perfectly giving a deep vibrant lively feeling."};
int S[Q];
char S1[Q];
int x;
int i;
char e, d;
cin>>x;
if(x=d){
cin>>Q;
for(i=0;i<array1[Q];i++)
cout << S[i]<<endl;
for(i=0;i<array1[Q];i++)
cout << S[i]<<endl;
}
Put the code you need help with here.
You seem to have a few misconceptions. In computers, everything is a number - even characters in text are numbers. There is no mechanism for determining if a number is just a number or if it is a character, because it could be either. It is up to the programmer to decide how to treat and interpret data.
Your characters are already in ASCII format, you just need to interpret them as numbers instead of characters. I don't understand why your program is taking input, so maybe I have misunderstood something.
Using arbitrary characters to represent your variables is one of the worst things you can do to yourself especially this early on. How about we start again by deleting all of the muck you have here and try using variable names that mean something to you. EDIT: Backing up your current progress is suggestible anytime someone recommends something this extreme.
Also, 'N', as used on Line 25, is undefined and 'Q' is redefined on Line 17. That's what I noticed without trying to compile anything.
@L B: It takes the input as into when the user inputs specific values it counts up till that value in the paragraph then it retrieves whatever letter is in it. thus output might be some type of secret message gathered up by the letters in the paragraph.
@Computer Geek: sorry the N was supposed to be a Q silly mistake. well what sort of logic should i use for such a program as the array1[] is a must not a choice of mine. but then after such how may tackle this array thus having the users enter values having the program gather which character it is in the array.
the encrypt part is different as it asks the user to input a line and i return it all in ascii values according to the ascii table but that part i can tackle later
@Line8 #define Q 2000
@Line17 int i, a=0, Q=0;
"Q" is being redeclared here. First as macro, Second as int variable. This is incorrect.
Post the full source after making the source compile successfully.
The array logic will not work for the reason that it does not have unique characters. I assume the encrypt logic is just indexing into this array. If so, the encrypted text/data cannot be decoded correctly.
@kannanmj: i fixed the Q part but you misunderstood the situation. see they input a value of the array and i am supposed to retrieve the letter or character at that value in the array. thats for the decrypt part the part of the program i actually wrote some of it.
Can you post the full source (with explanations/comments)? It will help in understanding what has been done so far and what help is needed in the remaining part of it?
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
usingnamespace std;
#define N 1000
void main(){
char array1[N]={"A gentle, dull flickering flame, burns in the marble hearth. Its dim light scarcely illuminates the small, cozy room with its quiet elegance. The dismal light plays softly causing shadows over the solitary figure of a wooden desk at which Allen was roaming through his memories. Thinking back in the past where he once had a friendship which was out righteously incredible. She was the girl of his dreams, in a way which she had everything he had ever sought out in a beautiful and clever girl. Most of all she had his heart. Her style was incredible in the way the outfits she would wear would match perfectly giving a deep vibrant lively feeling."};
int S[N];
int z;
int i, a, Q=0;
char e;
char d;
cin>>z;
while(z=='d'){
cin>>S[i];
for(i=0;i<=array1[N];i++)
cin>>S[a];
cout << i<<endl;
for(i=0;i<array1[N];i++)
cout << i<<endl;
}}
the "cin>> S[i]" won't work basically i'm trying to have the user input an araay of numbers.
That might be because i has an indeterminate value. You don't set i to anything before attempting to use it, so it very likely is not even in the bounds of the S array. I'm not sure how you know that it doesn't work though, since you never do anything with the value stored thusly.
Since z doesn't ever change inside your while loop, the loop is infinite.
Well then any suggestions on what i might be able to do to make my code better and more efficient other then the ones you have already mentioned. like how should the for loops look like and so on?
It would help if we knew exactly what you were trying to accomplish. This doesn't even look like an encrypter/decrypter it looks like you are trying to have the user manually type in each character for your "decrypter."
umm i am trying to have the user type out an array of numbers which fetches the characters from the paragraph array above and forms like random messages