Hello, I am working on a C# GUI in Visual Studio to write a program named ChatAWhile that 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.

The area codes given are 262, 414, 608, 715, 815, 920.
The Per Minute Rates are 0.07, 0.10, 0.05, 0.16, 0.24, 0.14.

here is the code I have thus far....

public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            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 };

            int validAreaCode;
            double totalCharge;
            double inputLength;
            //double areaCodeperMinuteRate = 0;

            validAreaCode = Convert.ToInt32(areaCode1.Text);

            inputLength = Convert.ToDouble(callLength.Text);



            for (int x = 0; x <= areaCode.Length; ++x)
            {

                totalCharge = perMinuteRate[x] * inputLength;
                Result.Text = String.Format("The area code is {0} and the cost of the call is {1}.", validAreaCode, totalCharge);
            }                
        }
    }

I know I am missing one thing! It displays exactly what I want it to, EXCEPT I think the equation is wrong because it is always multiplying zero instead of connecting to the second array. But I get an error message when I put in the perMinuteRate array instead of areaCodePerMinuteRate because you can't multiply an array and a double. Anyone have any hints or suggestions to help with what I should do??

Of course you can multiply an array with a number. You do it yourself in your loop on line 24.
What is the text of your error message?
How does your UI look like? Three textboxes? Put line 28 outside your for loop.

OK, guess I figured it out and I think it all boils down to an indexoutofrange exception!
If you you said that in the first place I could immediately have spotted the problem.
Change line 24 intofor (int x = 0; x < areaCode.Length; ++x) so <= becomes <

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.