Hi,
Im a beginning C++ student and having a very tuff time, but I have been trying for a few hours, and wanted come to you guys with my questions.
I have been working on this school project and have figured out every step but two.
Can anyone please help me.
Write a program that will read in an unknown number of words(of diff lengths) from a file words.txt program must do:
1.REad and display the word and move to tabs to the right.
2. insert "***" in the middle of the word
3. display the changed word and move two tabs to the right.
4. If the changed word is more than 8 characters long remove the characters that are past the 8th place, so it is exactly 8 characters. If the word is less that 8 characters, add enough letter "B"'s to the end so that it is exactly 8 characters long.
5. Display the changed word and move to tabs to the right.
6.Change the next to last character to a # sign and then put an ! point at the end of the word.
7.Display changed word.
8.Do this for all words read in.
9.Skip one line and display a count of all words read in.
So far I have everything done, and my stumbles are on #4 to add as many "B"'s necessary to the words that are less than 8 characters so they become exactly 8. Also on #6 I can add the explanation point to the end of the words that are longer that 8 characters but not to the ones that are shorter. When I add it into the program and starts to compile then stops. This is what I have so far.
Thanks, For the help all!
string word;
int count = 0;
int middle;
char fill;
char letter = 'B';
if (!infile)
{
cout << "An error has occurred while opening file" << endl;
exit (1);
}
while (!infile.eof())
{
infile >> word;
cout << word << "\t\t";
//print << word << endl;
middle = (word.length()/2);
word.insert(middle,"***");
cout << word << "\t\t";
if (word.length()>8)
{
word.erase (8,20);
cout << word << "\t\t";
word.replace(6,1, "#"),word.insert(8,"!");
cout << word << endl;
}
else if (word.length()<=8)
{
word.insert (8 - word.length(),"B");
cout << word << "\t\t";
word.replace(6,1,"#");
cout << word << endl;
}
count ++;
}
cout << count << endl;