Programming Exercises

   


In the following exercises, you are meant to change and add parts to the program in Listing 3.1 to make it perform the suggested actions.

1:

Instead of printing "Bye Bye!" as the last text on the command console before the program finishes, change the source code so that the program writes "Bye Bye. Have a good day!"

2:

Instead of typing a y to have the program print "Hello World!", have the user type Yes. Have the program inform the user about this by changing line 10.

3:

Instead of using the variable name answer to hold the input from the user, change the name to userInput.

4:

Let the program print out an additional line under "Bye Bye. Have a good day!" saying "The program is terminating."

5:

Declare another variable of type string called userName. Before the program prints "Do you want me to write the famous words?", have the program request the user to type in his or her name. After the user has entered his or her name, have the program read this name and store it in the userName variable. Then have the program print "Hello" followed by the content of the username. Tip: the last printout can be accomplished by typing

 System.Console.WriteLine("Hello" + userName); 

A typical execution of the program should result in the following output:

 Please type your name Deborah<enter> Hello Deborah Do you want me to write the famous words? Type Yes for yes; n for no. Then <enter>. Yes<enter> Hello World! Bye Bye. Have a good day! The program is terminating. 


   


C# Primer Plus
C Primer Plus (5th Edition)
ISBN: 0672326965
EAN: 2147483647
Year: 2000
Pages: 286
Authors: Stephen Prata

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net