So, in this program we have to
A. Count the number of each letter of the alphabet found in a character array and store these counts in an integer array
I understand that part but then it says we have to use the ASCII values which confuses me.
This is the file for reference:
" A frog walks into a bank and asks the teller, Miss Pattywack
for a loan. Miss Pattywack tells the frog,
"you must have collateral for the loan".
The frog pulls out of his pouch his porcelain people collection
and offers them as collateral.
Miss Pattywack looks at the figurines and tells the frog that
the collection is not acceptable.
The bank manager overhears the conversation and yells to the
teller - "It's a nick nack Pattywack, give the frog a loan!"
Use a for loop to examine each character in the character array
i. Use toupper to case the letter, so you are only dealing with capital letters
ii. If the character is a letter of the alphabet, increment the integer array in the position of the ASCII value of the character minus 65
1) 65 is the ASCII value of letter, 'A'
(1) If the character is A, 65-65 = 0 the position you want to increment for the character A
(2) If the character is C, 67-65 = 2 the position you want to increment for the character C
I have this so far:
void CountAlphabetCharacters(char chArray[MAX_CHARACTERS], int lengthOfArray)
{
int index;
for(index = 0; index <= lengthOfArray; index++)
{
chArray[index] = toupper(chArray[index]);
static_cast<int>(index);
}
}
That's all I have because that's all I understand. I mean, I understand how you get the ASCII value but I am so lost on how to actually make the for loop for this. Like I'm assuming you look at the characters from the file but I don't understand how you get that value you and keep going. I don't know if I make sense but I'm hoping I do and someone can help!! Thanks in advance.