0

hello

please help me it's important

i want code c++ convert from array to another "
example:
user enter : acb
array1[0]=a
array2[0]=1

and
array1[1]=b
array2[1]=2

array1[2]=c
array2[2]=3

**out put for user : 132
**
thanksthankthanthatht

3
Contributors
8
Replies
9
Views
5 Years
Discussion Span
Last Post by don't give up
0

you know that each letter of the English alphabet has a decimal value, which can be found in any ascii chart, such as .this one. So, to solve your problem all you have to do is subtract the ascii value of 'a' from whatever the user input, then add 1 since you want the values from 1-26, not 0-25. For example, if you enter the letter 'b', the answer would be 'b' - 'a' + 1 = 98 - 97 + 1 = 2 Here is a program example

int main()
{
   char n = '2';
   int value = n - 'a' + 1;
   printf("%d\n", value);
 }

 result:  2

You can now take the above one step further to apply it to the character array that you want. All you have to do is put that math algorithm in a loop .

Edited by Ancient Dragon

0

Thank u
But this just example
I want two array then if user enter any string
search in first array then convert to second array

0

So in your example if I enter the string "America" the program should output "gprs"?

In that case you need an array of 2d strings.

char stringlist[99][2][100];

The above will give you 99 2d character arrays. Each string can have up to 100 characters.
stringlist[0][0] = "America"
stringlist[0][1] = "gprs"
stringlist[1][0] = "France"
stringlist[1][1] = "abc"
stringlist[2][0] = "Germany"
stringlist[2][1] = "def"

etc for each string

Now when someone enters "Germany", your program searches stringlist[0][0] to stringlist[99][0] for that text. When found, just output the value in stringlist[x][1] (assuming x is a loop counter 0-99)

Edited by Ancient Dragon

0

general :)
if user entered "aman "
then process "search in array 1 and convert to array 2

output :
"isin"

"process (a convert to i ,, m convert to s , n convert to n)

general :)
if user entered "aman "
then process "search in array 1 and convert to array 2

output :
"isin"

"process (a convert to i ,, m convert to s , n convert to n)

0

So you are saying that the sequence of characters for array1 and array2 are already decided? In that case, your input string should be converted into a character array. Use a loop going through array1 to find the index of each character in the input, use that index to get the corresponding character from array2 and append that character to the output string.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.