Maha

Maha

  • NA
  • 0
  • 326.4k

What’s wrong with this program?

Oct 3 2012 2:01 PM
This program is producing correct output for "Belt" and "Tie" input. But for the other inputs ("Scarf" and "Cufflinks") program output is "No match found". Anyone can fix the error.

// Debug06-01
// Lists items for sale and their prices
using System;
public class DebugSix01
{
public static void Main()
{
string[] items = { "Belt", "Tie", "Scarf", "Cufflinks"};
double[] prices = { 29.00, 35.95, 18.50, 112.99 };

Console.Write("Items for sale: ");

string enterItem = Console.ReadLine();

int arrayPosition = Array.BinarySearch(items, enterItem);

if (arrayPosition < 0)
Console.WriteLine("No match found");
else
Console.WriteLine("Price {0}", prices[arrayPosition].ToString("c"));

Console.ReadKey();
}
}

Answers (2)