Help me to my Array Code [Prob : else function]

Help me to fix the else
for the output! in that code the output is correct my problem only is the else

when i enter the numbers that have in the array index ! the output shown the location w/ the else function :(

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
main(){
       int num[6];
       int index;
       int numb=0;

       printf("Enter Your Variables\n\n");
       
       for(index=0;index<6;index++){
       printf("The Variable in Index %d : ",index); 
       scanf("%d",&num[index]);                                 
       }
       
       printf("\nSearch the Number : ");
       scanf("%d", &numb);
       
       for(index=0;index<6;index++){
       
       if(numb==num[index])
       printf("\nThe Location of Variable %d is Index %d \n",num[index],index);
            
       else
       printf("The Number is Not Found");
}

getche();
}
Last edited on
As much as i hate to say it, i don't understand what you are trying to say. What exactly is the program doing wrong?
hey pal,
take one boolean let's say,
bool found = false;

make your for loop code like this,
1
2
3
4
5
6
7
8
9
10
for(index=0;index<6;index++)
{
	if(numb==num[index])
	{
		printf("\nThe Location of Variable %d is Index %d \n",num[index],index);
		found = true;
	}
}
if(!found)
	printf("Not Found");


hope you will understand this..
Last edited on
Topic archived. No new replies allowed.