0

This is my program, but it is giving me an error stating a Operator '*' cannot be applied to operands of type 'double[]' and 'double'. Can some one tell me how to fix this program.

The Chart-A-While phone company provides service to six codes and charges the following per minute rate for phone calls:
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 times for a call in minutes, then display the total cost of the call.

class Program
{
    static void Main()
        {
            //Declare variables
            int[] VaildAreaCode = { 262, 414, 608, 715, 815, 920 };
            double [] perminuterate = { 0.07, 0.10, 0.05, 0.16, 0.24, 0.14 };
            string inputString;
            double Totalcost;
            double lengthoftime;
            int AreaCode;
           
            Console.Write("Enter Area Code:\n");
            inputString = Console.ReadLine();
            AreaCode = Convert.ToInt32(inputString);

            Console.Write("Enter the length of Time:\n");
            inputString = Console.ReadLine();
            lengthoftime = Convert.ToInt32(inputString);

           Totalcost = perminuterate * lengthoftime;
            
               Console.WriteLine("AreaCode {0} Totalcost for {1}",
                    AreaCode, Totalcost.ToString("C"));
            

        }
    }

Edited by Ezzaral: Added code tags. Please use them to format any code that you post.

4
Contributors
12
Replies
13
Views
6 Years
Discussion Span
Last Post by ddanbe
0

'perminuterate' is an array which means it has multiple values. Which one did you want to multiply 'lengthoftime' by?

0

I want to display length of time for a call in minutes. I want to display a new vaiable nane totalcost to give the perminuterate * lengthoftime; The lenthoftime should be inputed by the user.

0

Please use code tags!
Instead of Totalcost = perminuterate * lengthoftime;
use Totalcost = perminuterate[index] * lengthoftime;
Now all you have to do is determine that index, wich depends on the area code input by the user and you can determine from your VaildAreaCode array.
Success!

0

sorry i donot know what to do. Please show me what to do.

0

Momerath is saying you cannot multiply some double value with double array value. No go.

You have this code:

double [] perminuterate = { 0.07, 0.10, 0.05, 0.16, 0.24, 0.14 };

What are these numbers mean?
And you have to select ONLY one value from this double array to multiply with user`s input, like:

double [] perminuterate = { 0.07, 0.10, 0.05, 0.16, 0.24, 0.14 };
double userInput = 0M;
double result = 0M;
if(double.TryParse(Console.ReadLine(), out userInput)
{
    //now you have user`s input in correct type, you only habe to select one value from array
    //but which one, this is up to you.
    //example: I will choose 3rd (0.05):
    result = userOutPut * perminuterate[2];
}
Console.WriteLine("Result is {0}.", result.Tostring());
Console.ReadLine();
0

The program is asking to display the total cost of the call. The program you gave does not work even if i use it as is. Can someone help me fix my program.

The Chart-A-While phone company provides service to six codes and charges the following per minute rate for phone calls:
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 times for a call in minutes, then display the total cost of the call.

int x;
            string inputString;
            double Totalcost;
            double lengthoftime;
            int AreaCode;
            bool isAreaCode;
            int[] VaildAreaCode = { 262, 414, 608, 715, 815, 920 };
            double[] perminuterate = { 0.07, 0.10, 0.05, 0.16, 0.24, 0.14 };

            Console.Write("Please Enter an Area Code: ");
            inputString = Console.ReadLine();
            AreaCode = Convert.ToInt32(inputString);

            Console.Write("Please Enter the length of Time:");
            inputString = Console.ReadLine();
            lengthoftime = Convert.ToInt32(inputString);

            x = 0;
            isAreaCode = false;
            while (x < VaildAreaCode.Length &&
               AreaCode != VaildAreaCode[x])
                ++x;
            if (x != VaildAreaCode.Length)
            {
                isAreaCode = true;
            }

            if (isAreaCode)
            {
                Totalcost = perminuterate * lengthoftime;

                Console.WriteLine("AreaCode {0} Totalcost for {1}",
                    AreaCode, Totalcost.ToString("C"));
            }

            else
                Console.WriteLine("No such AreaCode as {0}",
                   AreaCode);
           
           
        }
    }
}

Edited by Ezzaral: Added code tags. Please use them to format any code that you post.

0

Please do not get frustrated with me. I am a newbie with programming, and even though you made the suggestion with the index i am not understanding.

0

No CeeGee, I'm not in the least frustrated by you. But it seems to me that you are showing no effort(Tell me if I'm wrong) :)
Do you know the concept of an array and what an index is?

0

I am truly trying to the point of tears from frustration. I am trying to complete assignments with the helpo of the text but i am not understanding it all. And no i donot know what an index is.

0

sorry about not using code tag guys. just found out how to do it. Hope this is correct.

Edited by Ezzaral: Removed unnecessary TEX tags.

0

Nope.
Select your code and select the thing on the left of the TeX button.
Leran the concept of an array on MSDN.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.