Variables, Variables, and Variables
Let's get started
Today, we are starting our journey into development. This journey has to start somewhere. For this assignment, you will be making a program that demonstrates some programming fundamentals.
Objectives
- Ensure your development environment is setup
- Practice creating variables
- Practice working with user input
Requirements
Make sure you have followed the setup instructions for your computer's operating system
Follow this guide to review how to create and run C# applications
All your code should be placed inside the static void Main(string args[])
Setup
dotnet new sdg-console -o VariablesCS
Additional Resources
- SDG Quick Reference on Strings
- SDG Quick Reference on Numbers
- Turning in Assignments
- Types and variables
Reading Material
Explorer Mode
Create a new app that does the following.
Practice Creating Variables
- Create a variable (use your best judgment for type) that stores the
numberOfCupsOfCoffeethat you drink every day. - Create a variable (use your best judgment for type) called
fullNameand set it equal to your full name. - Create a variable (use your best judgment for type) called
todayand set it equal to today's date. - Use
Console.WriteLineand your variables,numberOfCupsOfCoffee,fullName, andtoday, to output all three on one line.
- Create a variable (use your best judgment for type) that stores the
Practice Getting Input From the User
- Ask the user for their name and store it in a variable named
userName. - Print out a greeting to the user, using their name.
- Ask the user for their name and store it in a variable named
Practice Getting Different Types of Input From the User
- Ask the user to input two numbers.
- Get the numbers as
strings usingConsole.ReadLine, store them in variables namedfirstNumberAsStringandsecondNumberAsString
Converting String Input Into Numbers
- Convert each
stringabove to adoubleusing double.Parse. Save the first value in a variable namedfirstOperandand the second value in a variable namedsecondOperand.
- Convert each
Doing Math
- Add the operand variables from above and save the results in a variable named
sum. - Subtract the
secondOperandvariable from thefirstOperandvariable and save the results in a variable nameddifference. - Multiply the operand variables and save the results in a variable named
product. - Divide the
firstOperandby thesecondOperandand save the results in a variable namedquotient. - Find the remainder when one operand is divided by the other and save the results in a variable named
remainder. See this page if you need to learn more about the modulo operator. - Use
Console.WriteLineto present the user, in a meaningful way, each of the values for thesum,difference,quotient,product, andremaindervariables. (e.g. perhaps one of your outputs is similar toIf you add 4 and 5 you get 9if4and5were the input)
- Add the operand variables from above and save the results in a variable named
Adventure Mode
- Using Logic
- Add some logic to your program that prints a different, special, greeting to the user if their name happens to be
Alice.
- Add some logic to your program that prints a different, special, greeting to the user if their name happens to be
- Using DateTime
- Use the type DateTime to represent the date variables.
- See the lesson on variables for some guidance on
DateTime
Epic Mode
- Move all of your code to a separate method (but keep it in the same file) and invoke it from the
Mainmethod.