Hello Anonymous2018,
At line 36 create an outer for loop based on the value of "argc" to process all the words.
The "cout' statements of "task 3" can be eliminated or commented out since this is done in "task 4. As Thomas1965 suggested add a variable inside the inner for loop to keep a count of the letters printed. Then after the inner for loop print the count on a separate line. Also do not forget to zero "count" before the next time through the inner for loop.
Hints:
The compiler does not care about extra white space. but the "cout" statements are better written as one line as an example:
cout << argc << endl;
. Then some day if you chain enough together in a "cout" statement you can break that up in separate lines as:
1 2 3 4
|
std::cout << "something to print "
<< aVariable
<< "More text"
<< another Variable << std::endl;
|
Instead of one long line, that might break up where you do not want it to, you break up the line where you want to an make it easier to read.
To shorten the program the "if/else" statements could be shortened to
1 2 3 4 5 6
|
if (argc < 2)
{
std::cout << "\n Command line does not contain enough words to work with." << std::endl;
std::this_thread::sleep_for(std::chrono::seconds(5)); // Requires header files "chrono" and "thread"
exit(1);
}
|
The second line puts a pause in the program to allow the user time to read the error message before the program ends, which could close the console window early. The only part you have to worry about is the 5 which is the number of seconds the pause is for. This is a whole number.
The third line could also be "return 1;" either works. Zero means that the program ended normally and any number greater than zero denotes a problem. With multiple "exit" or "return" statements the number can help you find where the problem is.
I use this code just before the "return" in main to keep the console open before the program ends:
1 2 3 4
|
// The next line may not be needid. If you have to press enter to see the prompt it is not needed.
//std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); // <--- Requires header file <limits>.
std::cout << "\n\n Press Enter to continue";
std::cin.get();
|
Hope that helps,
Andy