Quote:
...and I'm looking for help as usual
...
|
No problem. You did your homework and could use some assistance. Good attitude

.
I didn't check for correctness because officially I am at work now. However you need to be more accurate when you type.
Here is the first part with all the mistakes corrected:
Code:
#include <iomanip>
#include <cstring>
#include <fstream>
#include <utility>
#include <iostream>
using namespace std;
//Symbolic Constants
const int ARRAY_SIZE = 18;
// Function Prototypes
void Linear_Sort (int[], int);
void Selection_Sort (int [], int);
void Binary_Search (int [], int, int);
//************************************************** ***********************
int main ()
{
int NUM_ELS = 18;
int array [ARRAY_SIZE] = { 5658845, 8080152, 1005231, 4520125, 4562555,
6545231, 7895122, 5552012, 3852085, 8777541,
5050552, 7576651, 8451277, 7825877, 7881200,
1302850, 1250255, 4581002};
Linear_Sort (array, NUM_ELS);
//Selection_Sort (array, NUM_ELS);
//Binary_Search (int [], int, int);
return 0;
}
//************************************************** ************************
void Linear_Sort (int array[], int NUM_ELS)
{
int charge_num;
bool found = false;
cout << " Enter account charge number " << " : "<< endl;
cin >> charge_num;
for(int i = 0; i < NUM_ELS; i++)
{
if (array[i] == charge_num)
{
found = true;
break;
}
}
if (found)
{
cout << " Number is valid " << endl;
}
else
{
cout << " Number is invalid " << endl;
}
}
tips
- Try not to use "conio.h" and "getch()". Use :std::cin.get()" instead. In fact, it's even illegal in this part of the forum. That has a reason.
- Try not to use "#define" for constants. Use the "const" qualifier like I did. Otherwise we mix C and C++. Try not to do that when it's not required.
- Remove the:
Code:
if (found)
{
cout << " Number is valid " << endl;
}
else
{
cout << " Number is invalid " << endl;
}
This has nothing to do with Sorting or searching. It is just status message. Move it to its own function. As always, let functions do one thing and one thing only.
Okidoky, this should give you a fresh start

. Gotta go.