Question

Please debug this by fixing all the mistakes: C# // DebugFive03 // Finds whether a book...

Please debug this by fixing all the mistakes: C#

// DebugFive03
// Finds whether a book dealer carries a requested book
using System;
public class DebugFive03
{
    public static void Main()
    {
        string[] books = { "Catch-22", "Harry Potter", "Programming Using C#", "Rich Dad, Poor Dad", "The Deep", "Wizard of Oz" }; // fix []
        int x;
        string entryString;
        Console.Write("What book are you looking for?");
        entryString = Console.ReadLine();
        x = Array.BinarySearch(books, entryString); // change x to entryString
        if (x == 0)
        {
            Console.WriteLine("{0} not found", entryString);
        }
        else
        {
            Console.WriteLine("Yes, we carry {0}", entryString);
        }
    }
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1
// DebugFive03
// Finds whether a book dealer carries a requested book

using System;

public class DebugFive03
{
    public static void Main()
    {
        string[] books =
        {
            "Catch-22", "Harry Potter", "Programming Using C#", "Rich Dad, Poor Dad", "The Deep", "Wizard of Oz"
        }; // fix []
        int x;
        string entryString;
        Console.Write("What book are you looking for? ");
        entryString = Console.ReadLine();
        x = Array.BinarySearch(books, entryString); // change x to entryString
        if (x < 0)    // if entry is not found, then x is negative, not 0.
        {
            Console.WriteLine("{0} not found", entryString);
        }
        else
        {
            Console.WriteLine("Yes, we carry {0}", entryString);
        }
    }
}
Add a comment
Know the answer?
Add Answer to:
Please debug this by fixing all the mistakes: C# // DebugFive03 // Finds whether a book...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • PLEASE DEBUG THIS BY FIXING ALL THE MISTAKES IN C# // Creates a Car class //...

    PLEASE DEBUG THIS BY FIXING ALL THE MISTAKES IN C# // Creates a Car class // You can construct a Car using a price and color // or just a price, in which case a Car is black // or no parameters, in which case a Car is $10,000 and black using System; public class DebugSeven3 {    public static void Main()    {       Car myCar = Car("red", 32000);       Car yourCar = Car(14000);       Car theirCar = Car();...

  • C#, I am getting error placing them all in one file pls set them in the...

    C#, I am getting error placing them all in one file pls set them in the order that all 3 work in one file. Thanks //Program 1 using System; class MatrixLibrary { public static int[,] Matrix_Multi(int[,] a, int [,]b){ int r1= a.GetLength(0); int c1 = a.GetLength(1); int c2 = b.GetLength(1); int r2 = b.GetLength(0); if(r2 != c2){ Console.WriteLine("Matrices cannot be multiplied together.\n"); return null;    }else { int[,] c = new int[r1, c2]; for (int i = 0; i <...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT