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<<"MENU:"<<endl;
        cout<<"\t1.Linear Search\n\t2. Binary Search\n\t3.  Exit\n";
        cout<<"Enter your choice: ";
        cin>>choice;

    if (choice==1){
        cout<<"Please enter 10 numbers: "<<endl;
        for(int i=1;i<=10;i++)
        cin>>numbers[9];

        cout<<"Please enter 11th number: "<<endl;
        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){
           cout<<"11th number is not found in the previous ten numbers."<<endl;}

    }

*/




/*      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){
        cout<<"Please enter 10 numbers: "<<endl;
        for(int i=1;i<=10;i++)
        cin>>numbers[9];
        cout<<"Please enter 11th number: "<<endl;
        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);



}

Recommended Answers

All 2 Replies

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){
cout<<"Please enter 10 numbers: "<<endl;
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.
commented: Excellent points +36

Congratulations, Your code is rusted!!
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]
your code goes here
[/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]
[URL="http://www.daniweb.com/forums/thread78223.html"]Read Me: Read This Before Posting[/URL]

commented: "This document is a very briefed guide to check whether your coding practices in C++ are standard or not and to provide possible fix for the same. " Hi kiddo, if you don't speak English I would suggest getting someone who does to check over your work -4
commented: More pith from the "iamtheweener" +36
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.