#include<iostream>
#include<iomanip>
#include <fstream>
#include <ctime>
usingnamespace std;
//Function prototypes
bool SearchList(int[], int, int);
void selectionSort(int[],int);
void getNumber(int & );
int main()
{
constint ARRAY_SIZE = 18; // the Array size
int chargeAcct [ARRAY_SIZE]; // Array with 18 elements
int count = 0; // Loop counter variable
int accountNumber = 0; // stores the getNumber
ifstream inputFile; // Input File stream oblject
inputFile.open("chargeaccount.dat"); //Open data File
//Read the numbers from the files into the Array
// After this loop executes, the counter variable will hold
// the number of values that were stored in the array
while(count < ARRAY_SIZE&&inputFile >> chargeAcct[count])
count++;
//close File
inputFile.close();
// Display the numbers read
cout <<"The numbers are:";
for (int index=0; index < count; index++)
cout <<chargeAcct[index] << " ";
cout << endl;
system("pause");
return 0;
}
//sort array list
//Get Charge Account number from the user
void getNumber(int & accountNumber)
{
cout << "\nPlease Enter 7-digit Charge Account Number:";
cin >>accountNumber ;
//Search the array for number and determines if it is Valid or Invalid
bool found = SearchList(chargeAcct, ARRAY_SIZE, accountNumber);
if (found)
cout<<" The account number you entered is Valid.\n";
else
cout<<"The number you entered is Invalid."<<endl;
}
// This function performs binary search
bool SearchList(int list[], int numElems, int value)
{
long index = 0;
int position = -1;
bool found = false;
while (index < numElems && !found)
{
if (list[index] == value)
{
found = true;
position = index;
}
index++;
}
system("pause");
return found;
}
// This function uses selectionSort to sort the elements in ascending order
void selectionSort(int array[],int size)
{
int starScan, minIndex, minValue;
for (starScan = 0; starScan < (size-1); starScan++)
{
minIndex = starScan;
minValue = array[starScan];
for (int index = starScan +1; index < size; index++)
{
if (array [index] < minValue)
{
minValue = array[index];
minIndex = index;
}
}
array[minIndex] = array[starScan];
array[starScan] = minValue;
system("pause");
}
// This is my 3rd problem no one is help. Anytime I place a a problem no one dares to help
If you are using Microsoft Visual C++, double click on the error message and it will show you where the error occurred.
This is my 3rd problem no one is help. Anytime I place a a problem no one dares to help
When you are posting on this site, you will see some buttons on the right side. Above these buttons is written "Format:". Select your code and click on the '<>' button.
This will make your code look like code.
1 2 3 4 5
int main()
{
cout<<"Hello World"<<endl;
return 0;
}
chargeAcct is not defined inside the function - you should send a reference to chargeAcct as an argument to the function.
If you have compilation errors, please post them in full - the following is not very helpful, because it doesn't show the line number:
"error-expected-declaration-specifier"
Your code could also do with some proper indenting. Are you using an IDE? - if so it should be easy. My IDE has a "Reformat code" function which will do proper formatting after the code has been entered, & automatically does it as I type.