Skip to content

Step 5 - Finish off

You now have seen how to work with values in the terminal. Have a go at finishing off this program now. The remaining output needs you to get the distance remaining, to show the time remaining in the trip, the total distance covered, and the total time taken.

  • using static System.Convert;
    using static SplashKitSDK.SplashKit;
    const int MINUTES_PER_HOUR = 60;
    string name;
    string userInput;
    double distance, time;
    double speed;
    double remainingDistance, timeToDestination;
    double totalDistance, totalTime;
    Write("What is your name: ");
    name = ReadLine();
    WriteLine();
    WriteLine($"Hi {name}.");
    WriteLine();
    Write("How far have you travelled so far? Enter km: ");
    userInput = ReadLine();
    distance = ToDouble(userInput);
    Write("How long has it taken? Enter minutes: ");
    userInput = ReadLine();
    time = ToInt32(userInput);
    speed = distance / (time / MINUTES_PER_HOUR);
    WriteLine();
    WriteLine($"Your average speed is {speed} km/h");
    WriteLine();
    Write("How far do you have to go? Enter km: ");
    userInput = ReadLine();
    remainingDistance = ToDouble(userInput);
    timeToDestination = remainingDistance / speed * MINUTES_PER_HOUR;
    WriteLine($"You will take another {timeToDestination} minutes before you arrive");
    totalDistance = distance + remainingDistance;
    totalTime = time + timeToDestination;
    WriteLine($"Total distance will be {totalDistance} km");
    WriteLine($"Total time will be {totalTime} minutes");

Make sure to test your program and make sure that the values output are correct.

When you finish this you should feel confident that you can build some small terminal calculation programs on your own.