searching and sorting

ok all, another programming problem that the instructor didnt go over well enough. 3 more posts to follow, 1 with the actual problem, what im trying to do, and lastly my code thus far
1.Search Benchmarks: Write a program that has a sorted 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.
2.Sorting Benchmarks: Write a program that uses two identical arrays of at least 20 integers. It should call a function that uses the bubble sort algorithm to sort one of the arrays in ascending order. The function should keep a count of the number of exchanges it makes. The program then should call a function that uses the selection sort algorithm to sort the other array. It should also keep count of the number of exchanges it makes. Display these values on the screen.

for these, im trying to make it all done in one shot, code to follow
/*
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 (count = 0, count ++, count <20);
{
cout << array {count} << " ";
count = count +1;
}

cin >> number;
int linearsearch (number [], count = 0, count ++);
{
counta = counta+1;
if number = array{count}
{
cout << "the number is in memory position " << count << endl;
cout << "it took " << count << "passes to find it" << endl;
}
else
{
cout " the number is not in memory position " << count << endl;
}


cout <<"the numbers in ascending order are :" << endl;









}
error codes as follows:

1 IntelliSense: expected a declaration c:\documents and settings\allisa\my documents\visual studio 2010\projects\search benchmark\search benchmark\search benchmark.cpp 12 11 search benchmark
2 IntelliSense: expected a ';' c:\documents and settings\allisa\my documents\visual studio 2010\projects\search benchmark\search benchmark\search benchmark.cpp 20 12 search benchmark
3 IntelliSense: expected a ';' c:\documents and settings\allisa\my documents\visual studio 2010\projects\search benchmark\search benchmark\search benchmark.cpp 22 37 search benchmark
4 IntelliSense: expected a ';' c:\documents and settings\allisa\my documents\visual studio 2010\projects\search benchmark\search benchmark\search benchmark.cpp 24 17 search benchmark
5 IntelliSense: expected an expression c:\documents and settings\allisa\my documents\visual studio 2010\projects\search benchmark\search benchmark\search benchmark.cpp 29 28 search benchmark
6 IntelliSense: expected a ')' c:\documents and settings\allisa\my documents\visual studio 2010\projects\search benchmark\search benchmark\search benchmark.cpp 29 29 search benchmark
7 IntelliSense: expected a '(' c:\documents and settings\allisa\my documents\visual studio 2010\projects\search benchmark\search benchmark\search benchmark.cpp 32 6 search benchmark
8 IntelliSense: expected an expression c:\documents and settings\allisa\my documents\visual studio 2010\projects\search benchmark\search benchmark\search benchmark.cpp 53 1 search benchmark
put your code in the [c0de] [/c0de] tags, makes it a hell of alot easier to read.

1. int array {20}; should be int array[20]
2. same as above.
3.cout << array {count} << " "; should be cout <<array[count] << "" << endl; ( the endl; is not really nessesary)
4. count = count +1; could be changed to just count++ ( not part of ur error just a little somthing)

your errors seem to be with how you set up array.

Topic archived. No new replies allowed.