this is the instruction:
//Prompt the user with this menu:
1. Linear Search
2. Binary Search
3. Exit

Item 1 is similar to Exercise 1's item 5. This time however, the linearSearch function must be implemented using recursion.

Item 2 is what we call the Binary Search. As discussed, the implementation of binarySearch is iterative. //

below is my code:

which needs a lot of help.

``````#include <iostream.h>
#include <conio.h>

//bool linearSearch(int[] ,int , int );
//bool binarySearch(int[],int x, int n);

void main(){
int  choice, numbers[9], number ;

do{
cout<<"\t1.Linear Search\n\t2. Binary Search\n\t3.  Exit\n";
cin>>choice;

if (choice==1){
for(int i=1;i<=10;i++)
cin>>numbers[9];

cin>>number;

/*       bool flag= linearSearch(numbers[],number,a);
if (flag==true){

cout<<"11th number is found in the previous ten numbers."<<endl;}
else if(flag==false){

}

*/

/*      bool linearSearch(int nums[],int x, int n)
{

if(x==0);             // size of the array
if(int nums[x-1]==n);              // check if number in array is equal to 11th number
return true;
else
return linearSearch(int nums[],x-1,n);       //goes to next number in array
else
return false;
}

*/

}

else if(choice==2){
for(int i=1;i<=10;i++)
cin>>numbers[9];
cin>>number;

/*bool binarySearch(int[9],int x, int n)
{*/

/*
lower=numbers[0];
upper=numbers[9];
mid= (lower+upper)/2;

while (lower!=upper)

*/

}
}
while (choice!=3);

}
``````

Edited by Reverend Jim: Fixed formatting

3
Contributors
2
Replies
5
Views
9 Years
Discussion Span
Last Post by siddhant3s

Before even going into your logic i have a couple of things I can tell you

1-> Read the code-tags page carefully and learn to use them correctly. it would make your code much easier to read.
2-> don't use 'void main' and old style includes <.h>. Use int main(). Find out more about this in many threads on daniweb and on the web in general.
3->

``````if (choice==1){
for(int i=1;i<=10;i++)
cin>>numbers[9]; // This is wrong, you are writing each input on the last element on the array, numbers[9]. Make it numbers[i] and even for single line loops try to use {}, makes it more readable.
//And yes arrays are 0 indexed, so your loop has to change to loop from 0 - 9.``````
Excellent points

That means it uses the style of coding that was used aprox 13 years ago. You are using all the deprecated and non portable headers. You are using void main, which is a sin.
In short you are practicing everything that a Standard C++ developer should not.
I bet you would be using the old, crappy, good for nothing Turbo C++ compiler.

Here is [URL="http://siddhant3s.googlepages.com/how_to_tell_rusted_cpp.html"]a guide[/URL] which helps you to migrate to Standard C++ (the C++ which we use today)
If you are a school student, and your teacher teaches you rusted C++, you may still learn the standard C++ and use the rusted counterparts in your school.

The proper code tags are:
[noparse][code=cplusplus]
[/code]
[/noparse]

which needs a lot of help.

What do you mean by 'lot of help'? We won't be correcting and rewriting the program for you. If you are unable to find the errors in such a trivial code, consult [URL="http://www.daniweb.com/forums/thread70096.html"]a good text book[/URL] about C++

And as a Side note, did you bothered to read:
[URL="http://www.daniweb.com/forums/announcement8-2.html"]Announcement: We only give homework help to those who show effort [/URL]