Deciphering the Code

What does this code mean?I am a little confused about the toupper(item) part thx

1
2
3
4
5
6
  int place(char item)
{
char temp = toupper(item);
int index = (int)temp - 65;
return index;
}
Did you try looking up that function using your favorite search engine?

Seems to me that the code is all over the place

You have variables being declared into places where they don't fit.
Ints are for integers such as 1,2,3,4,5 ect.
Char is meant for single characters 'a' 'A'
so all you have here is variables that are undeclared being stored in.. well the wrong places. At-least that's how I interpret it, I could be wrong.

closed account (48T7M4Gy)
Look up a table of ASCII codes for characters. Combine that with the results of looking up what toupper does and the answer should become clear. If not then maybe run the program with a few values of item, both upper and lower case and see what the (return) value of index is.
Hello, I am trying to figure out what this function does also? From what I can gather, It seems that the int place w/ char item for letters is actually a number from ASCII table. Then this char letter is uppercase for different number in terms of the ASCII table for storage in char temp. Lastly, the new number/letter for char temp is subtracted by 65 for storage in int index. Finally, the index is final number that is returned in supposed array? I tried, but do not understand what is going on within the function. Thanks for any knowledge shared upon this...
1
2
3
4
5
6
  int place(char item)
{
char temp = toupper(item);
int index = (int)temp - 65;
return index;
}
closed account (48T7M4Gy)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>

int place(char item)
{
    char temp = toupper(item);
    std::cout << temp << ' ';
    
    int index = (int)temp - 65;
    return index;
}


int main()
{
    for ( char c = 'A'; c <= 'z'; c++)
    {
        std::cout << c << ' ' << place(c) << '\n';
    }
    
    std::cout << "END\n";
    return 0;
}
Topic archived. No new replies allowed.