/*
chCase Version2
*/
#include <iostream>
#include <cstdio>
usingnamespace std;
int main()
{
char ch[11];
int i;
while(true)
{
cout << "Please enter a letter (no more than ten, enter \".\" to exit): ";
gets(ch);
for(i = 0; ch[i]; i++)
{
//detect for a period
if(ch[i] == '.')
{
cout << ch;
break;
}
//detect for any error
elseif(!isalpha(ch[i])) continue;
//change case
else
{
islower(ch[i])?toupper(ch[i]):tolower(ch[i]);
if(i == 9) cout << "the new letters are: " << ch << "\n";
}
}
if(ch[i] == '.') break;
}
return 0;
}
im assuming it has something to do with one of these 2 lines:
char ch[11];
or
gets(ch);
because when i run it, it doesnt print anything except "Please enter a letter (no more than ten, enter "." to exit): ".
Try this instead. if(i == strlen(ch) - 1) cout << "the new letters are: " << ch << "\n"; or put cout << "the new letters are: " << ch << "\n"; before the return 0;. I personally avoid strlen(ch) for checking cstring length most of the time, because it relies on the '\0' character being present at the end of the string but in this case i guess it'll suffice.
Also if you're running this from an IDE which closes the console once the main returns put a cin.get() before the return 0; as well.