Toupper will not display letter, instead displays ASCII value

Greetings!

The program below ask a user to input the number of alphas which will be entered and then ask for entry of each character...
It is supposed to read each character and change any lower case characters to upper case and print out information on the characters where near the end, it is suppose to show the upper case values on screen.

For the life of me, probably because I am new to C++, I cannot figure out why my output is displaying the ASCII equivalent during the running of my last for loop near the end of the program.

The code will display the actual letter values everywhere else throughout the program when i ask the program to display the letters, yet, near the ending, it will only display the upper case and lower case ASCII values instead of the actual letters.

Can anyone give me some insight to the situation at hand and I do appreciate it very much!

[code]
#include<iostream>
#include<cctype>
#include<cstdlib>
using namespace std;

int main()
{
int Total_number;
char ch;

cout << "How many characters would you like to input? ";
cin >> Total_number;

char *myChars = new char[Total_number];//creates pointers to array instead of loading array with objects

int i, num_lower=0, num_punc=0;
for (i=0; i<Total_number; i++)//Loop below read charcaters in one-by-one
{
cout << "Enter Character " << i << ":" << endl;
cin >> myChars[i];

if ((isalpha(myChars[i])) && (myChars[i] > 'Z'))
{
num_lower = num_lower + 1;
}

if (ispunct(myChars[i]))
{
num_punc = num_punc + 1;
}
}
// ends for loop
cout << "Total number of characters read is :" << Total_number << endl;
cout << "The characters read in are: ";
for (i=0; i<Total_number; i++)
{
cout << myChars[i] << " ";
}
cout << endl;

cout << "The number of lower case characters is: " << num_lower << endl;
cout << "The number of punctuation characters is: " << num_punc << endl;

for (i=0; i<Total_number; i++)//read in and convert to upper
{
if (isalpha(myChars[i]))
{

if (islower(myChars[i]))
{
toupper(myChars[i]);
}
}

}

cout << "Output after conversion to upper is: ";
for (i=0; i<Total_number; i++)
{
cout << (toupper(myChars[i])) << " ";
}
cout << endl;
//this prints them out after conversion


}
/code]
toupper in <cctype> takes an int and returns an int. Notice how the example uses putchar to print the character:

http://www.cplusplus.com/reference/clibrary/cctype/toupper/

You can cast the result to a char or use the version of toupper in the <locale> header.

http://www.cplusplus.com/reference/std/locale/toupper/
Thank you, I will work on implementing this...
Topic archived. No new replies allowed.