Program is supposed to take any sentence and convert the lowercase to uppercase and uppercase to lowercase. It runs, but it isn't outputting. Any help would be appreciated.
#include <iostream>
#include <ctype.h> // allows the use of the functions toupper and tolower
usingnamespace std;
char changeCase(char arrayIN[]); // user-defined function to change case from upper-to-lower
int main ()
{
char arrayIN[256];
int i = 0;
int counter = 0;
int x,y;
{
cout << "Enter a sentence to test. Hit enter when you are done: ";
cin.get(arrayIN, 256);
}
while (arrayIN[256] != '\n');
{
changeCase(arrayIN);
cout << "Converted sentence: " << arrayIN << endl;
}
return 0;
}
char changeCase(char arrayIN[])
{
{for (int i = 0; i < 256; i++)
if(isupper(arrayIN[i]))
arrayIN[i] = tolower(arrayIN[i]);
else
arrayIN[i] = toupper(arrayIN[i]);
}
}
while (arrayIN[256] != '\n'); What are you trying to do here?
Also another big problem. in the function changeCase, you change to whatever, but then you want to print out the change whatever in main, how is main suppose to know you changed anything? It doesnt. You have to return it to be able to print it out in main, or just print it out in the actual function.
But I think the biggest question here is, Why the h are you using a character array and not a string?
Its waaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaay better with strings.
I played around with your program. Ive never done this upper/lowercase thing, so its been a bit of a challenge. But I got it to work but only if you print out the results in the actual function.
void changeCase(string ss); // user-defined function to change case from upper-to-lower
int main()
{
string ss;
int i = 0;
int counter = 0;
int x, y;
cout << "Enter a sentence to test. Hit enter when you are done: ";
getline(cin, ss);
changeCase(ss);
system("pause");
return 0;
}
void changeCase(string ss)
{
if (isupper(ss[0]))
{
ss[0] = tolower(ss[0]);
cout << "Converted sentence: " << ss << endl;
}
elseif (islower(ss[0]))
{
ss[0] = toupper(ss[0]);
cout << "Converted sentence: " << ss << endl;
}
}
If there is anything you dont understand please ask. But We'll need someone more experienced to show us how to return the string, and print it out in main :)