Need Help it wont print right

Write a program that has an array of at least 20 integers. It should

call a function that uses the linear search algorithm to locate one

of the values. The function should keep a count of the number of

comparisons it makes until it finds the value. The program then should

call a function that uses the binary search algorithm to locate the

same value. It should also keep count of the number of comparisons it

makes. Display these values on the screen.

/*
search benchmark.cpp
this program searchs through a array of 20 integers
*/

#include <iostream>
#include <string>
#include <iomanip>

using namespace std;

int array [20];
int count;
int number;
int counta;
int countb;

int main ()
{
int array [20] = {9, 18, 27, 36, 54, 45, 99, 63, 108, 72, 3, 6, 12, 15, 21, 24, 30, 33, 39, 42};
cout << " please pick one of the following numbers to search for" << endl;

for (int count = 0; count=19; count++);
{
cout << array[count] << "" << endl;
count = count +1;
cout << "Time in this loop "<<count << endl;
}

cin >> number;
int linearsearch = number; //(number [0], count=20, count++);

for (int count = 0 ; count = 20 ;count++)
{
counta = counta + 1;

if (number = array[count] )
{
cout << "the number is in memory position " << count << endl;
cout << "it took " << counta << "passes to find it" << endl;
}
}
if (number != linearsearch)
{
cout << " the number is not in memory position " << count << endl;
}


cout <<"the numbers in ascending order are :" << endl;
return 0;
}
The array elements run from 0 up to and including 19. check your for loop - it stops when it reaches 19. Also - remove the semicolon on that first for statement line.

Not sure why you are incrementing count in the for loop? It's already being incremented in the for statement.

If you're checking for equality, use == not the assignment operator =
Topic archived. No new replies allowed.