# Thread: Help with Converting between letters and numbers using arrays...

1. ## Help with Converting between letters and numbers using arrays...

I think i've got it but not too sure, and If anyone knows any other way to do this how could i do it?
Code:
```#include<iostream>
#include<cctype>
#include<string>
#include<fstream>
#include<iomanip>
using namespace std;

char integer_to_letter(int);
int letter_to_integer(char);

int main(int argc, char *argv[])
{
const int SIZE = 26;
int freq[SIZE] = {0};
char letter;
int index;
ifstream fin(argv[1]);
ofstream fout(argv[2]);
fin >> letter;
while(!fin.eof())
{
if(isalpha(letter))
{
index = letter_to_integer(tolower(letter));
freq[index]++;
}
fin >> letter;
}
fout << "Count the occurances of letters in a file" << endl
<< "producing a frequency" << endl << endl
<< "letter freq           letter freq" << endl
<< "------ -------------- ------ ---------------" << endl;
for(int i = 0; i < 13; i++)
{
char one = integer_to_letter(i);
tolower(one);
char two = integer_to_letter(i+13);
tolower(two);
fout << right << setw(6) << one << left << " "
<< setw(15) << freq[i] << " "
<< right << setw(6) << two << " "
<< left << freq[(i+13)] << endl;
}
fin.close();
fout.close();
return 0;
}

/*
* Name: letter_to_integer
* Purpose: Convert a letter to the corresponding number
* Receive: Data from a file
* Return: Number corresponding to the letter
*/
int letter_to_integer(char letter)
{
int index = (letter - 'a');
return index;
}

/*
* Name: integer_to_letter
* Purpose: Convert a number to the corresponding letter
* Receive: Data from a file
* Return: Letter corresponding to the number
*/
char integer_to_letter(int index)
{
return(static_cast<char>('a' + index));
}

/*
*/
{
cout << "\n";
cout << "\n";
cout << "\n";
}```

2. Code:
```for(int i = 0; i < 13; i++)
{
char one = integer_to_letter(i);
tolower(one);
char two = integer_to_letter(i+13);
tolower(two);```
What do those lines do?

3. I assume you want to do this so that you may order your words in alphabetical order. However, you can do this using the STL which is easier.

If this is not what you want to do then ignore this post.

4. Originally Posted by 7stud
Code:
```for(int i = 0; i < 13; i++)
{
char one = integer_to_letter(i);
tolower(one);
char two = integer_to_letter(i+13);
tolower(two);```
What do those lines do?
Click me!

5. Explanation: Tolower will return the ASCII value for the lowercase equivalent of the ASCII character chr, if it is a letter.
...and the question still stands: what do those lines do? Try this Welshy:
Code:
```char ch = 'A';
tolower(ch);
cout<<ch<<endl;```
and you'll see what I mean.