this is suppose to be a binary search to return the number of times a number is found in the array.............but for some reason it isnt calculating the correct number of times the number is found....already had my paper and pen out trying to find the error but it aint working ..help me please

//code

#include<stdio.h>
 
int main()
{
int target, mid,size,exit,i,count;
size=10;
count=0;
int array[10]={0,1,2,3,4,5,6,7,8,9};
mid=size/2;
printf("enter the number to be searched for");
scanf("%d",&target);
//to search for and calculate the number of times the number was found//
if(target >= mid)
{
i=mid;
while(i <= size)
{
if (target=array[i])
{
count++;}
i++;
}
}
else
{
i=0;
while(i<mid)
{
if(target=array[i])
{
count++;}
i++;
}
}
if (count>0){//execute if the number search for was found
printf("the number of times %d found is %d times",target,count);
}
else{//execute if number was not found
printf("%d was not found",target);}
scanf("%d",&exit);//to enter a number before the program exit
return 0;
}

The formatting is simply awful! If you reformat in more readible style and repost people may help you faster. Also do not use color tags -- use code tags and DaniWeb will add correct colors.

if ( target == array[i] )
commented: Yeah, Dave Sinkula, you are the boss. ;) +4

yeah Dave Sinkula you are the boss.........

you have goofed up == with = in many places of your code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.