I have this Lab for a class that I am taking.. It works as it suppose to... The problem I am having is that if I enter more than 11 char it goes all crazy.. I don't want it to do that...
#include <iostream>
#include <cstring>
using namespace std;
void cStringToUpper(char letters[]);
const int numLetters = 12;
int main()
{
char letters[numLetters];
char cont;
bool contProg = false;
do
{
for (int ct = 0; ct < numLetters; ct++)
{
letters[ct] = '\0';
}
cout << "Please enter up to 11 letters,:\n" << endl;
cStringToUpper(letters);
cout << "\n" << endl;
cout << "Do you wish to enter in another set of letters?\n"
"Press 'Y' to continue or 'Q' to end the program" << endl;
cin >> cont;
cout << "\n" << endl;
cin.ignore(200,'\n');
switch(cont)
{
case 'Q':
return 0;
break;
case 'y':
case 'Y':
contProg = true;
break;
default:
contProg = true;
cout << "'" << cont << "' is not a valid request!\n"
"Defaulting to main question:\n" << endl;
}
}while(contProg = true);
}
void cStringToUpper(char letters[])
{
int loopCount;
cin.getline(letters, numLetters);
letters[11]= '\0';
cout << "\n" << endl;
for (loopCount= 0; loopCount < numLetters; loopCount++)
{
if((letters[loopCount] >= 97) && (letters[loopCount] <= 122))
{
letters[loopCount]-=32;
cout << letters[loopCount];
}
else
{
cout << letters[loopCount];
}
}
}