Running a C++ Application from the Windows Command Prompt

1. Checking your setup. It’s important to read the Before You Begin section at www.deitel.com/books/cpp11fp/ to make sure that you’ve copied the book’s examples to your hard drive correctly.

2. Locating the completed application. Open a Command Prompt window. To change to the directory for the completed GuessNumber application, type cd C:examplesch01GuessNumberWindows, then press Enter (Fig. 1.7). The command cd is used to change directories.

Image

Fig. 1.7. Opening a Command Prompt window and changing the directory.

3. Running the GuessNumber application. Now that you are in the directory that contains the GuessNumber application, type the command GuessNumber (Fig. 1.8) and press Enter. [Note: GuessNumber.exe is the actual name of the application; however, Windows assumes the .exe extension by default.]

Image

Fig. 1.8. Running the GuessNumber application.

4. Entering your first guess. The application displays "Please type your first guess.", then displays a question mark (?) as a prompt on the next line (Fig. 1.8). At the prompt, enter 500 (Fig. 1.9).

Image

Fig. 1.9. Entering your first guess.

5. Entering another guess. The application displays "Too high. Try again.", meaning that the value you entered is greater than the number the application chose as the correct guess. So, you should enter a lower number for your next guess. At the prompt, enter 250 (Fig. 1.10). The application again displays "Too high. Try again.", because the value you entered is still greater than the number that the application chose as the correct guess.

Image

Fig. 1.10. Entering a second guess and receiving feedback.

6. Entering additional guesses. Continue to play the game by entering values until you guess the correct number. The application will display "Excellent! You guessed the number!" (Fig. 1.11).

Image

Fig. 1.11. Entering additional guesses and guessing the correct number.

7. Playing the game again or exiting the application. After you guess correctly, the application asks if you’d like to play another game (Fig. 1.11). At the "Would you like to play again (y or n)?" prompt, entering the one character y causes the application to choose a new number and displays the message "Please type your first guess." followed by a question mark prompt (Fig. 1.12) so you can make your first guess in the new game. Entering the character n ends the application and returns you to the application’s directory at the Command Prompt (Fig. 1.13). Each time you execute this application from the beginning (i.e., Step 3), it will choose the same numbers for you to guess.

Image

Fig. 1.12. Playing the game again.

Image

Fig. 1.13. Exiting the game.

8. Close the Command Prompt window.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.58.197.26