Perfect

In this stage, we’ll improve FitnessFrog by adding some features, doing input validation, and refactoring. We’ll also learn how to find .NET documentation.


Now, we want to beautify our interaction between console and user.

Do some output like this:

  • When user inputs <= 10, console shows "Better than nothing, am I right?"
  • When user inputs <= 30, console shows "Press your limit!"
  • When user inputs <= 60, console shows "You must be an Indonesia ninja warrior"
  • When user inputs <= 10, console shows "Okay, now you're just showing off"

We need multiple if-else statements.

using System;

namespace ConsoleApp1
{
    class Program
    {
        static void Main()
        {
            string entry;
            bool keepGoing = true;
            int totalWorkingTime = 0;

            while (keepGoing){
                // Prompt the for minutes exercised
                Console.WriteLine("Enter how many minutes you exercised: ");
                entry = Console.ReadLine(); 

                if (entry == "quit")
                {
                    keepGoing = false;
                }
                else
                {
                    int minutes = int.Parse(entry);

                    if (minutes <= 10)
                    {
                        Console.WriteLine("Better than nothing, am I right?");
                    }
                    else if (minutes <= 30)
                    {
                        Console.WriteLine("Press your limit!");
                    }
                    else if (minutes <= 60)
                    {
                        Console.WriteLine("You must be an Indonesia ninja warrior");
                    }
                    else
                    {
                        Console.WriteLine("Okay, now you're just showing off!");
                    }

                    // Add minutes exercised to a running total
                    totalWorkingTime = totalWorkingTime + minutes;

                    // Display the running total in minutes
                    Console.Write("Your total working minutes is " + totalWorkingTime + " minutes");
                }
            }
        }
    }
}

results matching ""

    No results matching ""