Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8631475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:13:28+00:00 2026-06-12T09:13:28+00:00

I was following a tutorial showing how to create a Binary search algorithm from

  • 0

I was following a tutorial showing how to create a Binary search algorithm from scratch. However I recieve the error “Use of unassigned local variable ‘Pivot'”. I’m new to the language and have only tried much simpler languages previously.

I apologise for the lack of internal documentation and appauling use of white space.

The error is near the bottom of the code labled using “//”

Here is the program:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Binary_Search_2
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] arr = new int[10];

            Random rnd = new Random();

            for (int i = 0; i < arr.Length; i++)
            {
                arr[i] = rnd.Next(1, 10);
            }

            Array.Sort(arr);
            for (int i = 0; i < arr.Length; i++)
            {
                Console.Write("{0},", arr[i]);
            }
            int Start = 0;
            int End = arr.Length;
            int Center = Start + End / 2;

            int Pivot;

            while (arr[6] > 0)
            {
                while (arr[6] < arr[Center])
                {
                    End = Center;
                    Center = (End + Start) / 2;
                    if (Pivot == arr[Center])
                    {
                        Console.WriteLine("The Index is {0}", arr[Center]);
                    }
                    break; 
                }

                while (arr[6] > arr[Center])
                {
                    Start = Center;
                    Center = (End + Start) / 2;
                    if (Pivot == arr[Center])  //**This is where the error occurs.** 
                    {
                        Console.WriteLine("The index is {0}", arr[Center]);
                    }
                }
            }
        }
    }
}

I’m sorry if this is actually something really simple but I don’t have anyone to teach me directly and I’m out of ideas.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T09:13:29+00:00Added an answer on June 12, 2026 at 9:13 am

    The error is caused by this line:

    int Pivot;
    

    The value of Pivot needs to be set before using it in an if statement.

    This indicates an error in your code: you check Pivot''s value in anif` statement, but you never assign to it. Look through the tutorial to find a line that looks like this:

    Pivot = ... // <<=== some expression here
    

    Most likely, you did not enter this line into your program when you followed the tutorial.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the following tutorial http://developer.android.com/resources/tutorials/views/hello-mapview.html in order to create a map view and
Following a tutorial from iTunes U on how to do face detection (the tutorial
I'm following the railstutorial.org tutorial about microposts. I'm having the following error: NoMethodError in
I've followed the following tutorial, in the simulator it works great, however on my
I've been following the tutorial at http://iphonebyradix.blogspot.com/2011/03/read-and-write-data-from-plist-file.html showing how to extract data from a
I just followed the following tutorial and works great. http://www.communityguides.eu/articles/6 However one thing his
I'm trying to create a single select listbox from Linq, however, I'm running into
I was following this tutorial to create an ElementMenu on the Microsoft Surface 2.
I've been following the tutorial at this site to create a jQuery CRUD form.
Im following the RoR tutorial by Michael Hartl and im at chapter 9.3 Showing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.