Chat-a-While Console App

[code language=”csharp”] using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;

#region Credit
/// <summary>
/// # # # # # # # # #
/// # Mark Hesser #
/// # Jan 4, 2018 #
/// # Chat a While #
/// # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
/// # The Chat-A-While phone company provides service to six area codes and charges the per-minute #
/// # rates for phone calls shown in Figure 6-25. Write a program named ChatAWhile that stores the #
/// # area codes and rates in parallel arrays and allows a user to enter an area code and the length #
/// # of time for a call in minutes, and then display the total cost of the call. #
/// # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
/// </summary>
#endregion

namespace ChatAWhile
{
class Phone
{
#region Declarations
static int[] areacodes = { 267, 412, 570, 610, 717, 814 };
static double[] pricePerMin = new double[6] { .09, .06, .075, .08, .07, .05, };
static int customerAreacode;
static double totalMinutesUsed, totalCost;
static bool quitMain = false;
static ConsoleKeyInfo kb;
#endregion

static void Main(string[] args)
{
Console.Title = "Chat-a-While";
while (!quitMain)
{
MainMessage();
Areacode();
Quit();
}
}
static void MainMessage()
{
Clear();
WriteLine("This program will prompt you for the area code you are dialing and how many" +
"\n minutes you want to talk, then will give you the total cost of that call" +
"\nFor a list of callable areacodes, enter 99.\n");
} //Opening Message
static void Areacode()
{
bool isAreacode = false, isServiceArea = false;

while (!isServiceArea) //Loop that checks to see if the zipcode entered is serviceable
{
Write("Area code: ");
while (!isAreacode) //Loop that checks if the user entered a zipcode
{
while (!Int32.TryParse(ReadLine(), out customerAreacode)) //Checks to see if the user entered an int
{
WriteLine("That is not a number. Please Try Again\n\a");
Write("Area code: ");
}
if (customerAreacode == 99)
{
DisplayAreacodes(); break;
}
if (Math.Floor(Math.Log10(customerAreacode) + 1) == 3) //Checks to see if input is 5 digits
{
isAreacode = true; //Exits input loop
}
else //Prompt the user for a new zipcode
{
isAreacode = false;
WriteLine("That is not a valid area code. Please Try Again\n\a");
Write("Area code: ");
}
}
if (customerAreacode == 99) break; //Breaks Loop if Display Area code key is entered

#region Search Array
int search = Array.BinarySearch(areacodes, customerAreacode); //Searches Array for servicable area code
if (search < 0)
{
WriteLine("That area is not in our serviceable area\a"); //Alerts users that the zipcode entered is not serviceable
isServiceArea = true;
}
else
{
Write("Minutes Used: ");
while (!Double.TryParse(ReadLine(), out totalMinutesUsed)) //Checks to see if the user entered a double
{
WriteLine("That is not a number. Please Try Again\n\a");
Write("Minutes Used: ");
}
totalCost = pricePerMin[search] * totalMinutesUsed;
WriteLine("\nThe Total Cost for {0} minutes is {1:C}", totalMinutesUsed, totalCost); //Provides the user with the Total Cost for that Area code
isServiceArea = true;
}
#endregion
}
} //Main Input Loop with Calculations
static void DisplayAreacodes() //Displays all Possible Area codes
{
Clear();
WriteLine("Availble Area codes\n");
for (int i = 0; i < areacodes.Length; i++)
{
WriteLine("{0} – {1:C} per minute", areacodes[i], pricePerMin[i]);
}
}
static void Quit()
{
Write("\nWould you like to enter another Area code? (y/n) ");

#region Quit?
kb = Console.ReadKey(); //Listens for Key
if (kb.Key == ConsoleKey.N) //Ends Program
{
quitMain = true;
}
else if (kb.Key == ConsoleKey.Y) //Restarts the program
{
quitMain = false;
}
else //Still Quits the program
{
Console.WriteLine("\nYou didn’t hit Y or N."); Console.WriteLine("I’m going to assume you said No.");
Console.WriteLine("Press Any Key Quit"); Console.ReadKey();
quitMain = true; //Ends Program
}
#endregion
} //Asks the user if they would like to enter another area code
}
}
[/code]