# Thread: convert Num to Char**HELP PLS**

1. ## convert Num to Char**HELP PLS**

hi, when i add something to the code there are some error, can someone please let me know or if possbile please correct it for me by letting me know as i want to know what is wrong with the code....

when i run it the output is 66 62 12 15 28a s string, when i input Johnny.

my target is to convert those number of string to characters as i assign A is 00, B is 01....till.......Z is 26. if the number >= 26, for example 44 is larger so 44%26 = 18 so the character output will be S.

here is the code

Code:
```    stringstream numbers;

/* Insert integer into stringstream*/
numbers <<numLowerCaseLetter(name)<<sumAscii(name)<<lastValue<<counter<<sum;

/* Convert stringstream into string.*/
string str = numbers.str();

if(str.size() % 2 == 0)
{
for(int i = 0; i < str[i]; i=i+2)
{
numOfTwo[i]=str.substr(i,2);
cout<<numOfTwo[i]<<" ";
}
}
else
{

str.size()+1;
str.append( 1, '0' );

for(int i = 0; i < str[i]; i=i+2)
{
numOfTwo[i]=str.substr(i,2);
cout<<numOfTwo[i]<<" ";
}

}

// Final solution which convert number into character by producing a code.

for(int i = 0; numOfTwo[i]; i++)
{
if(numOfTwo[i] >= 26)
{
modLeft = numOfTwo % 26;
cout<< something[modLeft];
}
else
{
cout<<something[numOfTwo[i]];
}```
when i run the code, this error comes out

In function `int main()':
could not convert `numOfTwo[i]' to `bool'
no match for 'operator>=' in 'numOfTwo[i] >= 26'
invalid operands of types `std::string[15]' and `int' to binary `operator%'
no match for 'operator[]' in 'something[numOfTwo[i]]'
syntax error before `{' token

2. if numOfTwo is an array of ints, then you can't assign a string to an int.
Code:
` numOfTwo[i]= str.substr(i,2);<<<this won't work!`
Code:
` numOfTwo[i]= atoi(str.substr(i,2).c_str());`

3. Originally Posted by gtr_s15
my target is to convert those number of string to characters as i assign A is 00, B is 01....till.......Z is 26. if the number >= 26, for example 44 is larger so 44%26 = 18 so the character output will be S.
Are you trying to do something like this?
Code:
```#include <iostream>
#include <string>
#include <cctype>
using namespace std;

int main()
{
std::string text("Johnny");
cout << text << " = ";
for ( const char *ch = text.c_str(); *ch; ++ch )
{
// assume a character set with a contiguous alphabet, such as ASCII
int value = toupper(*ch) - 'A';
cout << value << ' ';
}
cout << endl;
return 0;
}

/* my output
9 14 7 13 13 24
*/```