Skip to content

Step 2 - Read the user's name

Best first step is to build something small, then we can grow the program our from that start. Let’s just get the first two messages handled - reading the user’s name and displaying it. So we want to see this at the end:

What is your name: Andrew
Hi Andrew.
  1. Open your terminal, and setup your project

    Terminal window
    # Move you your code projects folder
    cd ~/Documents/Code # or cd /c/Users/andrew/Documents/Code
    # Create and move into a folder for the project
    mkdir TravelCalculator
    cd TravelCalculator
    # Create a blank dotnet project
    dotnet new console
    # Add the SplashKit library
    dotnet add package splashkit
    # Open in VS Code
    code .
  2. Add the using directives to access the SplashKit and Convert code.

    • At this point you should just have these two lines of code.

      using static System.Convert;
      using static SplashKitSDK.SplashKit;

    As you look at this you want to see if there are any values that will change. We will need to create variables to store these.

    Looking at the first lines, I imagine that we may have different users run this. So their name may change.

  3. Add the code to create a name variable - then we can think about how we use this.

  4. Review the messages we want to output. To start we want to output the message "What is your name: ", read the text and user enters, then output a blank line and the greeting text "Hi " followed by the user’s name.

    Looking back at the terminal methods, we have methods to output text (Write and WriteLine), and read text from the user (ReadLine). Use these to display the prompt, and output the required messages.

    • using static System.Convert;
      using static SplashKitSDK.SplashKit;
      string name;
      Write("What is your name: ");
      name = ReadLine();
      WriteLine();
      WriteLine($"Hi {name}.");
      WriteLine();
  5. Now compile and run the program to see the output. Check it against what we were aiming to achieve.