+ 2
Can i write a pragram such that for any name given input by keyboard output will be in such that it indiacate the no of alphabet
for ex-if input is 'pranav' then it's out put should be '15,17,1,13,1,21'
13 Answers
+ 3
yes you can.
if i was at home i could have create it for you so i just tell you how would i do it.
1. create 2 arrays and a variable.
char alphabet = 'a','b', etc...
int * alphabet_numbers
int counter = 1
2. then you get user input.
3. splits string to chars [ which you dont need because string is bunch of chars ]
4. create dynamic alphabet_variable with the size of your input ( i think input.size() ).
5. use a - z loop.
6. check in the loop if char equal to one of a - z in the loop, if not counter+1. if yes store counter into alphabet_numbers and set counter for 1.
7. output numbers :)
EDIT: youll need to use another for loop for the array index. ( i forgot that sry )
+ 2
i have made it for you. ( using Jared Bird Method )
https://code.sololearn.com/cIc6obw8nbXq/?ref=app
+ 2
@Cain,
Good work your code works well. đ
One more related tip:
You used the correct decimals for the ASCII codes for the lettersâ.
You can also use the hex values, ie 65 == 0x41.
More importantlyâ you can use the character.
So instead of:
output = output - 65;
you can use:
output = output - 'A';
The code will work the same.
The reason I suggest this is I think it makes the code more readable.
đ
+ 1
There is a quicker way:
For each character subtract the value of 'a'
then add 1 //you want a to became 1, not 0
Then output.
// you may have to use a cast, unless data is in a char array or string
you probably want think about what happens if character is not a letter or is upper case.
+ 1
i didnt think about that đ„
+ 1
That's why we share ideas đ
The number of times I have finished or got halfway through writing code for something, then realised that there was a better way. đ©
Too many!
+ 1
hahahha i never tried to convert char to int so i didnt think about that :(
but i have used a - z loop so...
+ 1
ohhhh my bad. its converting from character to ascii.
ill fix that.
+ 1
fixed.
+ 1
thanks for your tips.
0
thankou so much cain eviatar and jared bird
0
but it's giving output wrong as more than 26 which is not posible according to my question
0
sure