NEED HELP FOR ERROR MESSAGES

//I am two months old C++ student and I need a help pls. keep getting this error message //"error-expected-declaration-specifier"


//PLESAE CAN SOMEONE TAKE A LOOK AT MY CODE AND POINT ME OUT WHERE THE ERROR /ORIGINATES FROM ?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include<iostream>
#include<iomanip>
#include <fstream>
#include <ctime>
using namespace std;

//Function prototypes
bool SearchList(int[], int, int);
void selectionSort(int[],int);
void getNumber(int & );


int main()

{
const int 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

Last edited on
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;
}
Ok great
I am having hard time with this program. The problem is with line 53 and 54
Last edited on
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.

HTH
Last edited on
Thank you very much but I am just a beginner so need your help as I have sat on this since Friday. It is due tonite.

I coded the program nicely until I was asked to convert for the file to be read from input data file
. Now am totally exhausted so need a help
Last edited on
Topic archived. No new replies allowed.