0

This is my program:

using System;
using static System.Console;

class MoveEstimator
{

    static void Main(string[] args)
    {
        const double BASE_RATE = 250.00;
        const double HOUR_RATE = 150.00;
        const double COST_MILE = 2.00;
        string amtHoursAsString;
        double amtHours;
        string numMilesAsString;
        double numMiles;
        double totalOfMove;
        Write("Enter amount of hours >> ");
        amtHoursAsString = ReadLine();
        amtHours = Convert.ToDouble(amtHoursAsString);
        Write("Enter number of miles >> ");
        numMilesAsString = ReadLine();
        numMiles = Convert.ToDouble(numMilesAsString);
        totalOfMove = (amtHours * HOUR_RATE) + (numMiles * COST_MILE) + BASE_RATE;

        WriteLine( "Your estimated move cost is " + totalOfMove);
        return;

    }

}

It works for the input, but the program closes before it gives me the output. I'm new at this as you can tell. I'm learning it with a book so I just want an entry level answer so that I can work my way up. I just need to know what is wrong with my WriteLine statement. Thank you so much in advance!

neontapir
  • 4,698
  • 3
  • 37
  • 52
  • 2
    Your application finishes, and closes. If you want it to "wait" for user input before closing, then you can add Console.ReadLine(); before the return. This will require the user to press enter before closing. If you run your app as-is in a separate command prompt (by running cmd and then navigating to your EXE and running it), it should not auto close and you will see your output. – Tom Feb 02 '18 at 22:34
  • Better option than `Console.ReadLine()` is `Console.ReadKey(true);` – Joel Coehoorn Feb 02 '18 at 22:52
  • *"the program closes before it gives me the output"* Actually, it gives you the output and then *immediately* closes, so you don't have time to see it. I always add the following to the end of a console app: `Console.Write("\nPress any key to exit..."); Console.ReadKey();`. You can put that in place of `return`. – Rufus L Feb 02 '18 at 22:52
  • "Actually, it gives you the output and then immediately closes, so you don't have time to see it." Indeed that is such a vexing behavior of commandline programming, a lot of compilers go and add a Console.ReadKey() or similar during debug builds. Yours apparently does not. – Christopher Feb 02 '18 at 23:03

0 Answers0