Hi
I'm writing a small pice of code that takes numbers and convert it to string.
so that's what I got
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
int main() {
char letter;
char letter1;
char letter2;
cin >> letter;
cin >>letter1;
int sum = letter * 128 + letter1;
cout << sum << endl;
int eq;
eq = sum;
cin >> letter2;
eq = (sum * 128 + letter2);
cout << eq;
return 0;
}
|
It's just a scratch of the idea that I want to do.
So let me explain what's going on here.
The it asks the user to enter a letter, say 'w' , which it's value is 119
then enter another letter, say 'o' which value is 111
then it do the equation, which is take the value of the first letter multiple it by 128 then add it to the value of the second letter.
So, one question here. How can I make it does this process in a For loop, or any kind of loop??
--
Then I have the second part which is the other way around. That is when the user enter a numbers then the code convert these numbers to a string.
251394404 - "d"
1964018 - "rd"
15343 - "ord"
119 - "word"
so what's happening here is the it divide each time by 128. But I can't do that in a code, I would really need help with that part.
and Thanks :)