To keep it short, my class just started doing arrays and this was one of our homework assignments. So I made up my array, console input, constants, and everything was working fine and dandy, but like I said there's that one format issue toward the bottom.
This is the program code:
If I input 262 for the area code and 7 for the minutes I want it to somehow output $0.49, but if I try to put anything such as ("C0") or this ("C2") it just either makes the output zeros or rounds it to 0.50!
using System;
class ChatAWhile
{
static void Main()
{
// declaring the variables for the program.
double[] areaCode;
areaCode = new double[6];
const double TWO_SIXTY_TWO = 0.07, FOUR_FOURTEEN = 0.10, SIX_HUNDRED_EIGHT = 0.05, SEVEN_FIFTEEN = 0.16, EIGHT_FIFTEEN = 0.24, NINE_TWENTY = 0.14;
double minutesUserInput;
int areaCodeUserInput;
double totalCost = 0;
int x;
areaCode[0] = 262;
areaCode[1] = 414;
areaCode[2] = 608;
areaCode[3] = 715;
areaCode[4] = 815;
areaCode[5] = 920;
Console.WriteLine("Chat-A-While Telephone Company");
Console.WriteLine();
Console.Write("Enter the area code: ");
// areaCodeAsString = Console.ReadLine();
areaCodeUserInput = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter the calling time(minutes): ");
minutesUserInput = Convert.ToDouble(Console.ReadLine());
Console.WriteLine();
// using a switch statement to match user minutes with area code.
switch(areaCodeUserInput)
{
case 262:
totalCost = TWO_SIXTY_TWO * minutesUserInput;
break;
case 414:
totalCost = FOUR_FOURTEEN * minutesUserInput;
break;
case 608:
totalCost = SIX_HUNDRED_EIGHT * minutesUserInput;
break;
case 715:
totalCost = SEVEN_FIFTEEN * minutesUserInput;
break;
case 815:
totalCost = EIGHT_FIFTEEN * minutesUserInput;
break;
case 920:
totalCost = NINE_TWENTY * minutesUserInput;
break;
}
// Was trying to explore different options here............
// string s = String.Format("{0:0.00}", totalCost);
x = Array.BinarySearch(areaCode, areaCodeUserInput);
if (x < 0)
Console.WriteLine("Our company does not cover the area code {0}. Please enter a valid area code.",
areaCodeUserInput);
else
Console.WriteLine("The cost of a phone call to area code {0} is: " + totalCost.ToString("C") +
x, areaCode[x].ToString());
Console.Read();
}
}

New Topic/Question
Reply




MultiQuote




|