Solutions for those exercises.
Questions
-
The method
ReadLine()
reads a whole line and interprets its content as an integer (int
) type.- Yes
- No
-
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.
-
In C#, what is the “escape character”? Why is it useful?
-
In C#, what is the name of the method used to read input from the user?
Problems
-
Write a program that performs the following steps:
- Asks user to enter any number between 1 and 100
- Multiplies the number user enters by 2
- 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.
-
Write statements that prompt the user to enter their favorite food and store the input value in a variable.
-
Write statements that prompt the user to enter 3 numbers, and then return their average.
-
Write statements that prompt the user to enter a positive number, and then output all the odd numbers between 0 and that number.
-
Write a series of statements that:
- Declare an
int
variable nameduserAge
, - Display on the screen a message asking the user to enter his or her age,
- 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.
- Declare an