Solutions for those exercises.

Questions

  1. The method ReadLine() reads a whole line and interprets its content as an integer (int) type.

    • Yes
    • No
  2. A _____ can be used in repetition structures (such as loops) to indicate the end of data entry.

    • Property
    • using directive
    • Sentinel value
    • None of the above.
  3. In C#, what is the “escape character”? Why is it useful?

  4. In C#, what is the name of the method used to read input from the user?

Problems

  1. Write a program that performs the following steps:

    1. Asks user to enter any number between 1 and 100
    2. Multiplies the number user enters by 2
    3. Displays the result of the calculation on the screen

    Here is an example of execution, where the user input is underlined, and hitting “enter” is represented by ↵:

    Hello user!
     
    Please enter a number between 1 and 100: 3͟2͟↵
     
    32 multiplied by 2 is 64!

    Run your program a few times and use different numbers in range 1-100 to verify the program works as intended.

  2. Write statements that prompt the user to enter their favorite food and store the input value in a variable.

  3. Write statements that prompt the user to enter 3 numbers, and then return their average.

  4. Write statements that prompt the user to enter a positive number, and then output all the odd numbers between 0 and that number.​

  5. Write a series of statements that:

    1. Declare an int variable named userAge,
    2. Display on the screen a message asking the user to enter his or her age,
    3. Read the value entered by the user and store it in the userAge variable.

    You can add statement(s) performing intermediate steps if you want.