Create a C# console program where you will implement variables that are needed f
ID: 3599754 • Letter: C
Question
Create a C# console program where you will implement variables that are needed for this program and will implement the code within Main and any required static methods. Create an array that stores 6 area codes as string and a parallel array that will store 6 per-minutes rates as double. Use initializers to set the values of each array according to the following table:
Declare variables in Main for a boolean found, string area code, string minutes. call a static method to calculate the total for the minutes and pass to it the two arrays, and the variables found, area and minutes all by reference. In the method: Prompt the user to enter an area code. Loop through the area array to find a match to the entered area code. When the code is found in the array ask the user for the length of time for a call in minutes. Calculate the cost as minutes * rate from the corresponding rate array element. Display the cost to the console as currency. Set found to true. If when control returns to Main, the area code was not found from Main display "Sorry - no calls allowed to area XXX".
You should format your output to look something like the following:
If the area you enter is not in the array it will look like this:
What area code are you calling?402
Sorry - no calls allowed to area 402
Press any key to continue . . .
Explanation / Answer
using System.IO;
using System;
//author : Pankaj Rana
class Program
{
// static variable used to get calll rate
static double rate=0;
// static variable used to get ccallCharges
static double callCharges(int callDuration){
return callDuration * rate ;
}
// static variable used to get ccallCharges and set call rate
static bool checkAreaCode(int code,string[] AreaCodes,double [] callRates){
string areaCode = code.ToString();
bool result=false;
for(int i=0;i<6;i++){
//checking for area code is matched or not
//if matched then setting result true
if(AreaCodes[i] == areaCode)
{
//setting call rate to static variable rate
rate=Convert.ToDouble(callRates[i]);
result= true;
}
}
return result;
}
public static void Main(String[] args)
{
bool found;
string [] AreaCodes = new string [] { "262", "414", "608", "715","815","920" };
double[] callCharge=new double[]{ 0.07,0.10,0.05,0.16,0.24,0.14};
Console.WriteLine("What area code are you calling?");
string userInput1 = Console.ReadLine();
int AreaCode = Convert.ToInt32(userInput1);
found= checkAreaCode(AreaCode,AreaCodes,callCharge);
//check area code is matched or not againt user input code
if(found== true){
//if macthed the take call duration input
Console.WriteLine(" How many minutes is your call?"+" ");
string userInput2 = Console.ReadLine();
int duration = Convert.ToInt32(userInput2);
Console.WriteLine("Your phone call to area "+ AreaCode+" costs $ "+ rate+" per minute");
Console.WriteLine(" For "+duration +" minutes the total is $ "+ callCharges(duration));
Console.WriteLine("Press any key to continue . . . ");
}
else{
Console.Write("Sorry - no calls allowed to area"+AreaCode+" ");
}
}
}