我不相信我遗漏任何括号或半冒号。不确定这个错误还有什么可以诚实的。有任何想法吗?
请提前原谅凌乱的笔记,但无论如何 - 我留下了一张纸条,我收到了预期的不合格ID错误
#include <iostream>
#include <fstream>
using namespace std;
int binarySearch(const int [], int, int);
const int ARRAY_SIZE = 1000; // Array size
int main()
{
int accountNumbers[ARRAY_SIZE]; // Array with 1000 elements
double accountBalances[ARRAY_SIZE]; // Array with 1000 elements
int count = 0; // Input file stream object
ifstream inputFile;
ofstream outputFile;
// Open the file.
inputFile.open("FinalNumbers.txt");
outputFile.open("Final_Random_Accounts_Sorted_Mazzei_Chris.txt");
// Read the numbers from the file into the array
while (count < ARRAY_SIZE && inputFile >> accountNumbers[count] >> accountBalances[count] ) {
count++;
}
inputFile.close();
int tempAccNumber = 0;
int tempAccBalance = 0;
for(int j = 0; j < ARRAY_SIZE - 1 ; ++j)
for(int i = 0; i < ARRAY_SIZE - 1; ++i)
if (accountNumbers[i] > accountNumbers [i + 1])
{
tempAccNumber = accountNumbers[i];
accountNumbers[i] = accountNumbers[i +1];
accountNumbers[i + 1] = tempAccNumber;
tempAccBalance = accountBalances[i];
accountBalances[i] = accountBalances[i + 1];
accountBalances[i + 1] = tempAccBalance;
}
// Move assorted numbers to new file
for (int i = 0; i < ARRAY_SIZE; i++) {
outputFile << accountNumbers[i] << endl;
outputFile << accountBalances[i] << endl;
}
outputFile.close();
cout << "done" << endl;
int accNUM;
int results;
cout << "Enter an account number to be found: ";
cin >> accNUM;
results = binarySearch(accountNumbers, ARRAY_SIZE, accNUM);
cout << "id is found at " << results;
}
int binarySearch(const int array[], int size, int value);
// expected unqualified-id error with bracket below.
{
int first = 0,
last = size - 1,
middle,
position = - 1;
bool found = false;
while (!found && first <= last) {
middle = (first + last) / 2;
if (array[middle] == value) {
found = true;
position = middle;
}
else if (array[middle] > value)
last = middle - 1;
else
first = middle + 1;
}
return position;
}