In my second version of my program that will help create a secure password for the user I am attempting to have it create an acronym from a phrase that the user types in. One problem that I am having is whenever I display the acronym it shows the acronym but then it shows some unprintable characters and then the phrase. What did I do wrong? Here is the quick code I wrote to do it so I haven't really worried about neatness for now.
Code:#include <iostream> using namespace std; int main() { int c=1; char again, phrase[40], acronym[40]; do { cout << "Enter phrase (40 character limit): "; cin.getline(phrase, 40, '\n'); for (int i=0; i < 40; i++) { if (i == 0) //if it is the first letter of the phrase acronym[0] = phrase[0]; else if (phrase[i] == ' ') //if it is inbetween words use the first letter in the following word { acronym[c] = phrase[i+1]; c++; } } cout << "Acronym is " << acronym << "\nAgain?: "; cin >> again; cin.ignore(80, '\n'); //just incase they typed in 'yes', 'Yes', 'YES'... } while (again == 'y' || again == 'Y'); return 0; }



LinkBack URL
About LinkBacks


