Warm-up Exercises
-
Write a program that performs the following steps:
-
Ask user to enter any number between 1 and 100
-
Multiply the number user enters by 2
-
Display the result of the calculation at the screen
Here is a sample of a program output that performs these steps:
Hello user!
Please enter a number between 1 and 100: 32
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 (running program 3 - 5 times is sufficient).
-
Prompt the user to enter their favorite food and store the input value in a variable.
-
Prompt the user to enter 3 numbers, and then return their average.
-
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:
a) Declare an int variable named userAge, b) Display on the screen a message asking the user to enter his or her age, c) 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.
Questions
- Method ReadLine() reads a whole line and interprets its content as of integer (int) type.
- Yes
- No
- A _____ can be used in repetition structures 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?