1. ## Binary Search Help

Code:
```#include<stdio.h>
#include<stdlib.h>
main()
{
int count,count2,count3,count4,array[50],temp,search,high=49,low=0,location=25;
srand(2);
for(count=0;count<50;count++)
{
array[count]=rand()%1000;
}
for(count3=0;count3<count;count3++)
{
for(count2=0;count2<count-1;count2++)
{
if(array[count2]>array[count2+1])
{
temp=array[count2];
array[count2]=array[count2+1];
array[count2+1]=temp;
}
}
}
for(count2=0;count2<count;count2++)
printf("%i\n",array[count2]);
printf("Enter a number and I will tell you it's location.");
scanf("%i", &search);
while(search!=array[location]||(low-high)==1)
{
if(array[location]==search)
printf("%i was located in location %i\n",search,location);
if(array[location]!=search)
printf("Between %i and %i\n",low,high);
if(array[location]<search)
{
low=location;
location=(low+high)/2;
}
else
{
high=location;
location=(low+high)/2;
}
}```

2. Learn what a comment is.

Learn to use constants either MACRO or real constants. Do not use variable where it should be an constant.

Code:
`for(count3=0;count3<count;count3++)`
Learn to ask a specific question.

Tim S.

3. Get a good binary search:
Code:
```int binarySearch(int array[], int goal, int left, int right) {
int lo, mid, hi;
lo=left;
hi=right;
while (lo <= hi) {
mid = (lo + hi) / 2;
if(goal < array[mid])
hi = mid-1;
else if(goal > array[mid])
lo = mid+1;
else
return mid;
}
return -1;
}```
If the return value from the binary search function is >-1, then it will return the index number to the goal, in the array[]. Otherwise, the value was not found.

If the array being searched is not sorted, the function may fail.

4. ## Hello

Originally Posted by stahta01
Learn what a comment is.

Learn to use constants either MACRO or real constants. Do not use variable where it should be an constant.

Code:
`for(count3=0;count3<count;count3++)`
Learn to ask a specific question.

Tim S.
Learn what a jerk is.
You are one.

This is my first time on here asking you "experts" a question.
Sorry for not knowing how to code like a master, and not knowing everything about C.
BTW, My problem with the code was that in the binary search is that it was not running properly every time I entered a number, it would enter into an infinite loop..But I managed to fix my problem... Sorry for the troubles.

5. Thanks for the help adak!

6. Zach, Welcome to the forum!

When you come to a programming forum, like many other kinds of fourms, people are unusually curt - that's just the nature of impersonal communication, and limited time - and no way can the keyboard keep up with our thoughts we want to express.

Don't let anything get personal with you, and please, don't get into name calling, flame wars, etc. Try hard to let it all roll off you, like water off a duck's back. You can't do it all the time, (me neither), but it helps a lot to try.

And you're welcome.

7. FYI, posting code without any accompanying explanation of the problem or asking a question is like walking up to a colleague's desk, slamming a piece of paper with code and your thread title at the top on it, down in front of them and then immediately briskly walking away.
You need to have courtesy to politely ask for help with a specific problem or you will get an appropriately blunt response at best.

That said...
What your while loop does is continue looping while either of these things are true:
Code:
```search!=array[location]
(low-high)==1)```
Do you really want it to keep going if that last part were true? Also, when would it even become true?

So, helping you is being a jerk.

How To Ask Questions The Smart Way

Tim S.

9. Your reply was good Tim. New members have a hard time dealing with "concentrated" replies, and think it's personal. In R/L it would be impolite, of course, but here, we need to concentrate our communication a bit to offset the slower throughput of a forum.

You were being helpful, but he didn't know it.

10. Sorry about that, I just dident know about the fourm form.. SEE WHAT I DID THERE!! ANYHOO... My apologies to Tim, and thanks for the help to a new member... I managed to get the code to work after a few hours of tinkering with it...

11. Originally Posted by Zachery Montoya
Sorry about that, I just dident know about the fourm form.. SEE WHAT I DID THERE!! ANYHOO... My apologies to Tim, and thanks for the help to a new member... I managed to get the code to work after a few hours of tinkering with it...
Something to keep in mind when dealing with us coder types is that we work with very precise grammar and spelling day in and day out. After a while it does affect the way we communicate... we become very direct and often blunt but most often no offense is intended.