I have been working on this program for a few days now. I am very new to C++, and as you will probably be able to tell, am very confused about the correct syntax for several occasions (also sorry about my sloppy form :c). I believe the current problem with what I have so far deals with the binary algorithm I'm using. Any help with any portion of the code will greatly appreciated.
Assignment details:
Develop a modularized C++ application program that reads a list of scores from an input data file into an array, displays the list of the scores stored in the arrays, sorts the list in ascending order using a selection sort algorithm, and searches the list for a given score using a binary search algorithm.
Heres what I have so far:
#include <iostream>
#include <fstream>
using namespace std;
ifstream infile(infile.txt); //Just 7 numbers in a text document, space delimited.
int main()
{
void doRead(int scores[]);
void doSort(int scores[]);
int doBin(int scores[], int search); //I'm almost positive the problem is here.. I just can't pin point it.
void doPrint(int scores[]);
while(yn != 'n')
{
cout<<"Enter a search item, a score: ";
cin>>search;
temp = doBin(scores[], search); //Seems to always get a 3 or a 7 from this function.
if (temp == -1)
cout<<"Item not found!"<<endl;
else{
cout<<"Search is successful. "<<search<<" is the "<<temp;
switch(temp)
{
case 0:
cout<<"st list element."<<endl;
break;
case 1:
cout<<"nd list element."<<endl;
break;
case 2:
cout<<"rd list element."<<endl;
break;
default:
cout<<"th list element."<<endl;
}
}
cout<<"Would you like to search for another item? (y/n)";
cin>>yn;