ne555,
We were not communicating. My apologies!
I examined the code as presented in the example in the book before opening a new project. Because all of the previous CLR console programs failed to keep the window open in the absence of
Console::ReadLine();, I was confident that this example would exhibit the same behavior. Building and starting the program
without debug confirmed this analysis. For the purpose of this reply I need to add the fact that the book has not provided any solution other than using
Console::ReadLine(); to keep the window open as of this stage of instruction.
The second problem presents a slightly more complicated explanation. I had the correct initial analysis for what may be the wrong reasons. The final
return 0; statement presented a no brainer for me. It returns control to the system by terminating the program. Prior to this exercise the only other use of a return statement I had encountered was a function returning a value to the program.
This left me with two possible interpretations. I explored both possibilities in my head and came to the same conclusion for both interpretations. At this point I had not opened a new project. I was still thinking out the results of line-by-line execution of the code in the book, playing computer before typing any code. Please put all of this in the context of my very shallow programming experience and the very early stages of the book. I am currently on page 158 of a 1231 page book.
My reasoning for one interpretation was that the braces containing the if block represented a complete instruction set. As such the behavior would be similar to a function executing and returning a value. This seemed to indicate that the
return 0; statement would serve to exit the code block and continue with the next executable statement (not terminate the program). No matter what data is entered, it seemed to point to the eventual execution of the last
WriteLine statement. I saw nothing to prevent this. Your previous statement
Nope, there are return 0; inside the if statements. |
indicates that I had the wrong analysis.
The second interpretation led me through this thought process. If the other analysis is incorrect, what else could it mean? Does the return value represent a Boolean value? I "played computer" with the premise that this is a Boolean value. A Boolean false evaluation is zero in integer form.
I pondered the behavior of the if blocks. If the condition evaluates to false (0), the block is ignored and the next executable statement executes. I had a little trouble reconciling the results of the condition evaluating to true. Without a doubt the code inside the block would execute. What about the
return 0; statement at the end of the block? Would that cause the false condition to execute also? In the unlikely event that both the false and the true options would execute, that seemed to point to the last
WriteLine executing also.
At this point the only thing to do was to type the code, build the program, and run it to observe the results.
¿How did you observe the second problem (always "You did not enter a letter") if the window would not stay open? |
I am in the habit of repeating whatever action causes a window to close prematurely in an attempt to read the text. On the first repeat, I noticed that there were two lines of text where there should be only one. After about a couple dozen repetitions, I had deciphered all the text.
As for executing
Console::ReadLine(); twice for capital letter, small letter, and not a letter, I noticed that also. It is senseless to me. However, testing the program with multiple combinations of additions and deletions of the
Console::ReadLine(); and
return 0; statements left me with only one combination which exhibited the desired behavior for all three categories of data tested by the program. I provided input data for all three categories to test each modification of the code I tried.
The link you provided contains some functions I am not familiar with. I will test them to see if they work in the example code. System("pause") is not supported by C++/CLI as far as I can tell. There is a passage contained in the link which states that Windows is non-standard. When attempting to research some of the code in Visual C++ I find that to be true. In many cases I find that code examples and explanations only work in native C++. So far I have had no trouble with any of the examples using native C++. Several of the C++/CLI examples have required modification to run properly.
This book has the structure of a text book which begs for classroom lecture to supplement many of the topics. There appears to be too much information that requires previous knowledge or is left to research in order to clearly understand what is going on.
Anyway... I believe I have answered your questions. Ask more if you wish. I await your reply.
regards,
drpepper