Question #40070

a programmer is asked to do an invoice of the telephone account for a subscriber. the input to this program is the telephone number dialed and the length of call in minutes (integer). the fees are 50 cents for the first minute and 30 cents for every minute thereafter. the telephone number and cost of the call must be displayed for every call.the total amount due by the subscriber must be shown at the end of the invoice. a telephone number of 9999 serves as sentinel.

Expert's answer

using System;
namespace Question_Telephone
{
    class Program
    {
        static void Main(string[] args)
        {
            string telephone = "";
            int time = 0;
            do
            {
                Console.Clear();
                Console.WriteLine("Enter telephone number:");
                telephone = Console.ReadLine();
                Console.WriteLine("Enter the length of call in minutes (integer):");
                if (!Int32.TryParse(Console.ReadLine(), out time) || time < 0)
                {
                    Console.WriteLine("Wrong input! Press any key to continue...");
                    Console.ReadKey();
                    return;
                }
                if (telephone == "9999") Console.WriteLine("Sentinel number doesn't need money...");
                else
                {
                    Console.WriteLine("Total amount for \"{1}\" is:{0,6:0.##}$", time > 0 ? 0.5 + 0.3 * (time - 1) : 0, telephone);
                }
                Console.WriteLine("Press ESC to exit or anything else to continue...");
            } while (Console.ReadKey().Key != ConsoleKey.Escape);
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS