Array to uppercase

HMMMM This looks like what I want, to change lower case to upper case. Could someone give me a hint as to where I am going wrong?

It is in fact school work, I can not use an algorithm, and i do not want a correction so to speak. I do need to be nudged along though.
Thank you.
Todd

#include<iostream>

using namespace std;


int main()
{
const int SIZE = 81; //+1 for null terminated.....
char userInput[SIZE];

cout << "Enter a string of characters\n";
cout<<"and i will change lower case to upper case." << endl;

cin.getline(userInput, SIZE);
for (int i = 0; userInput[i] <SIZE; i++)
{
if (userInput[i] >= 97 && userInput[i] <= 122);
userInput[i]-=32;
}
cout << userInput;

system("pause");
return 0;

}
why don't you tell us what went wrong?
If you run the program all that is returned is the user input string as is. nothing is changed to uppercase.

I am trying to change lower to uppercase by changing the ascii value in a loop
Last edited on
if (userInput[i] >= 97 && userInput[i] <= 122);
Don't put a semicolon a the end, there. That semicolon immediately after the if predicate tells the compiler "if the predicate is true, do nothing".
Do this instead:
1
2
if (predicate)
    do_something;
If you want to avoid confusion, you can also always keep the braces:
1
2
3
if (predicate){
    do_something;
}
Thanks for the catch, but there is still no change in the string......


Todd
closed account (E0p9LyTq)
chops wrote:
change lower case to upper case. Could someone give me a hint


Using the <cctype> function toupper() in your for loop might help.

http://www.cplusplus.com/reference/cctype/toupper/
toupper is not allowable, hence the ascii vaue subtraction.
Doh! Totally missed it the first time. Your for predicate says userInput[i] < SIZE instead of i < SIZE
YOU NAILED IT!!!

This tinny little code was driving me crazy!!!!

Thank you helios
Topic archived. No new replies allowed.