Hello guys! I am stuck in this program. Its giving errors. Basically, we have to encode
"Hello World". The way to do this is by using the last 4 numbers of my roll number. Example scenario:
If roll no is 18F-0805. So Code 1 is 0+8+1 = 9 and Code 2 is 0+5+1 = 6.
Now For Capital letters Code is 9 and For Small letters, Code is 6.
Input: Hello World! H will turn to Q (an increase of 9) but small letters will increment by 6
Output: Qkrru Fuxrj!
you are trying to assign a string to a character. a character holds 1 byte.
line 13... should be string line = "Hello World". For that you need <string> included.
you also need to make generate code take a string, of course, to match.
stringvariable[x] works just as you have it, once you do that.
pure addition won't work, by the way.
'W'+9 is not 'F', its going to be some other ascii value.
you want to force it to wrap back around, which needs a little more math.
there are cute ways to do it but for now a simple if letter+9 > 'Z' then ... will do it.
if you want to get really shifty you can do this
char uptbl[26];
for(i = 0; i < 26; i++)
uptbl[i] = ('A' + i +9)%26;
and just do a lookup to get your values. lookup is uptbl[upperlettervalue-'A']
so 'A'-'A' is zero, uptbl[0] is 'A'+9 ... right? and similar for lower case... just don't hard code the 9, its here to show you the way, make it your variable in the code.
these are the instruction!
ROLL NO: 18F-WXYZ
Now write a Program in which you declare 2 integers a=W+X+1 and b=Y+Z+1. Now create 2
Pointers, P1 will point to ‘a’ and P2 will point to ‘b’. Then write a function void
GenerateCode(int* P1,int* P2,char* line). This function takes a line by reference and changes it into the encrypted line.
my function declaration will be as mentioned!
Is there any problem in line 19?
compilers cannot read human intentions.
this says
if(line[i] is e or true or true or true or true)
you need to put each compare explicitly
if(line[i] == 'e' || line[i]=='o' || etc...)
x +=3 is the same as x = x+3. use the shortcut operators when you can its easier to read.
I am not convinced your new approach is correct either, see what you get with the conditional bug fixed.
I said that :)
you need to wrap back around. if letter + value > z then ... something is the most simple to understand fix.
so what goes in there..
if its > z, then you have to get to z (say its y, then you add 1, and you still have 8 if you were adding 9, so now its a+8) so you need to know the amount left over to wrap around...
Your code is bizarre. Why are you passing a and b as pointers? There's no reason for that. And why are you making it so it can only encode the string "Hello World"? That's retarded.
You should pass a and b as plain ints. And you should use isupper() and islower() to tell if the character is upper or lowercase.