Write a program that lets the user enter a charge account number. The program should determine if the number is valid by checking for it in the following list:
5658845 4520125 7895122 8777541 8451277 1302850
8080152 4562555 5552012 5050552 7825877 1250255
1005231 6545231 3852085 7576651 7881200 4581002
The list of numbers above should be initialized in a single dimensional array. A simple linear search should be used to locate the number entered by the user. If the user enters a number that is in the array, the program should display a message saying the number is valid. If the user enters a number that is not in the array the program should display a message indicating the number is invalid.
Charge Account Validation Modification
Modify the program so it performs a binary search to locate valid account numbers. Use the selection sort algorithm to sort the array before the binary search is performed.
That was the question and below is what I did as solution but can't seem to make it work and I'm looking for help as usual
Code:
#include <iomanip>
#include <cstring>
#include <fstream>
#include <utility>
#include <conio.h>
//******************************************************************************
//Symbolic Constants
#define 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};
// Function calling.
Linear_Sort (array, NUM_ELS);
Selection_Sort (array, NUM_ELS);
//Binary_Search (int [], int, int);
cout << endl << endl << endl << "Press Any Key to Continue...";
getch ();
return 0;
//*****************************************************************************
void Linear_Sort (int array[], int NUM_ELS);
{
int charge_num;
int i;
bool found = false;
cout << " Enter account charge number " << " : "<< endl;
cin >> charge_num;
for(int i = 0; i < 18; i++)
{
if (array[i] == charge_num){
found = true;
break;
}
}
if (found){
cout << " Number is valid " << endl;
}
else{
cout << " Number is invalid " << endl;
}
}
//******************************************************************************
void Selection_Sort (int array[], int NUM_ELS);
{
int start_Scan;
int min_Index;
int min_Value;
for(start_Scan = 0; start_Scan < (NUM_ELS - 1); start_Scan++)
{
min_Index = start_Scan;
min_Value = array[start_Scan];
for (int index = start_Scan + 1; index < NUM_ELS; index++)
{
if (array[index] < min_Value)
{
min_Value = array[index];
min_Index = index;
}
}
array[min_Index] = array[start_Scan];
array[start_Scan] = min_Value;
}
}
}
//******************************************************************************
//void Binary_Search (int [], int, int);
//while(i < 18 && !found)
//{
//if (array [i] == charge_num )
//{
// found = true;
//}
// i++;
//}
// if (found)
// cout << " Number is valid " << endl;
//else
// cout << " Number is invalid " << endl;
// cout << " arraynum " << arraynum[0];
//cout << endl << endl << endl << "Press Any Key to Continue...";
//getch ();
//return 0;
//}
Thanks