Question: / / Define parallel arrays for area codes and rates int [ ] areaCodes = { 2 6 2 , 4 1 4 , 6

// Define parallel arrays for area codes and rates
int[] areaCodes ={262,414,608,715,815,920};
double[] rates ={0.07,0.10,0.05,0.16,0.24,0.14};
// Ask for user input
Console.Write("Enter the area code: ");
int areaCode = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter the length of the call in minutes: ");
double minutes = Convert.ToDouble(Console.ReadLine());
// Find the area code in the array and calculate the cost
bool areaCodeFound = false;
for (int i =0; i < areaCodes.Length; i++)
{
if (areaCode == areaCodes[i])
{
double cost = rates[i]* minutes;
Console.WriteLine($"Your phone call to area {areaCode} costs ${rates[i]:C} per minute");
Console.WriteLine($"For {minutes} minutes the total is ${cost:C}");
areaCodeFound = true;
break;
}
}
// Area code not found
if (!areaCodeFound)
{
Console.WriteLine($"Sorry - no calls allowed to area {areaCode}.");
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!