Prime b

Prime b

  • NA
  • 810
  • 339k

Another array problem

Jan 7 2012 1:31 PM
The problem

Th e Chat-A-While phone company provides service to six
area codes and charges the per-minute rates for phone calls
shown in the accompanying table.
Area           Code Per-Minute Rate ($)
262                       0.07
414                       0.10
608                       0.05
715                       0.16
815                       0.24
920                       0.14
Write a program that allows a user to enter an area code and
the length of time for a call in minutes, then display the total
cost of the call.


totalCharge use of unassigned local variable . please help



What I have done so far


            int[] areaCode = new int[] { 262, 414, 608, 715, 815, 920 };
            double[] perMinuteRate = new double[] { 0.07, 0.10, 0.05, 0.16, 0.24, 0.14 };
            string inputString, inputString1;
            int validAreaCode;
            double totalCharge, inputLength;
           
           
            double areaCodexPerMinuteRate = 0;


            Console.WriteLine("Pleas enter zipcode ");
            inputString = Console.ReadLine();
            validAreaCode = Convert.ToInt32(inputString);

            Console.WriteLine("Please enter the  length of the call");
            inputString1 = Console.ReadLine();
            inputLength = Convert.ToDouble(inputString1);

            bool found = false;

            for (int x = 0; x < areaCode.Length; ++x)
            {
                if( validAreaCode == areaCode[x])
                {
                    found = true;
                    areaCodexPerMinuteRate = perMinuteRate[x];
                    totalCharge = areaCodexPerMinuteRate * inputLength;
           
                }
            }
            if (found)
            {
                Console.WriteLine(" The call was {0} long and it will cost you {1}", inputLength, totalCharge);
            }
            else
                Console.WriteLine(" We do not support such zipcode");
               

Answers (5)