-2

Im having a compiler error: "expected unqualified id before '{' token" on line 94

It seems all my brackets are in tact but I can't find a solution to this problem

#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;

const int ALIASFILE_LINE_COUNT =16;
const float USERBONUSLEVEL = 75.09;
const float USERAWARDLEVEL = 80.72;
const int USERBONUS = 5;
const int USERAWARD = 8;
const int ARRAY_SIZE = 20;
void selectionSortDec( double list[], int length);
void selectionSortAsc(double list[], int length);
void printArray( const double list[],const int length);
void loadArray(fstream& in, double list[],const int length);
string inputFileName;
string outputFileName;
string Time;
string Name;
string Alias;
string UserID;
ifstream inFile;
ofstream outfile;
double price=0, sum=0, max=0, min =0;
double average=0, roundedaverage=0;
double ITEM_COUNT=0;
double number=0;





int main()
{
 double myArray[ARRAY_SIZE]={0};
 int index=3;
cout <<"\n\nproject 3"<<endl;

 cout<<"Enter full name:";
  getline(cin, Name);       // full name
  cout<<"Enter \Alias\:";
   cin >> Alias;            //alias
    //gender
  cout<<"Enter user ID: ";
   cin >> UserID;               // ID// rating
  cout<<"Enter items file name:";
  cin >> inputFileName;






 inFile.open(inputFileName.c_str());
  if(!inFile){
    cout<<"\nProject 1 ERROR Opening Input File!! Exiting!\n\n"<<endl;
    return 0;
}





    outputFileName =Alias + ".txt";
outfile.open(outputFileName.c_str());
    if(!outfile){
    cout<<"\nProject 1 ERROR Opening OUTPUT File!! Exiting!\n\n"<<endl;
    return 0;
    }

cout<<"full name:" << setw(12)<<Name<<endl;
cout<<"Alias: " <<setw(12)<<Alias<<endl;
cout<<"UserID : " <<setw(12)<<UserID<<endl;

 outfile<<"full name:" << setw(12)<<Name<<endl;
outfile<<"Alias: " <<setw(12)<<Alias<<endl;
outfile<<"UserID : " <<setw(12)<<UserID<<endl;




inFile>>number;
inFile>> price;
inFile>> ITEM_COUNT;
getline(inFile, Name);

}


{

void printArray( const double list[],const int length){
for(int index=0; index<length; index++)
    cout << list[index] <<"  ";

   }

    void loadArray(fstream& in, double list[],const int length){

       for(int index=0; index<length; index++)
        in>>list[index];
}



cout <<"\n___________________________________________________________\n";
cout <<setw(6)<<"\nWEEK\t\t(ordered low to high -->)  ";
void selectionSortAsc(double list[], int length){
double temp;
int index;
int smallestIndex;
int minIndex;

for (index = 0; index < length - 1; index++)
{
    smallestIndex = index;

    for (minIndex = index + 1; minIndex < length; minIndex++)
        if (list[minIndex] < list[smallestIndex])
            smallestIndex = minIndex;

    temp = list[smallestIndex];
    list[smallestIndex] = list[index];
    list[index] = temp;
 }
}




cout     <<"\n____________________________________________________________\n";
  cout <<"\nWEEK avg       high      low";
void selectionSortDec( double list[], int length){

 int index=0, smallestIndex=0, minIndex=0;
 double temp=0;
 for (index = 0; index < length - 1; index++)

    smallestIndex = index;
    for (minIndex = index + 1; minIndex > length; minIndex++)
        if (list[minIndex] > list[smallestIndex])
            smallestIndex = minIndex;


    temp = list[smallestIndex];
    list[smallestIndex] = list[index];
    list[index] = temp;
cout <<"\n___________________________________________________________\n";
cout<<setw(14);

cout <<"\n___________________________________________________________\n";





inFile.close() ;
outfile.close() ;
    }
      cout<<"\n\n\n";
   }
  return 0;
Mad Physicist
  • 107,652
  • 25
  • 181
  • 264
  • 2
    Too long, please provide shorter code that still has this issue. https://stackoverflow.com/help/mcve – javaLover Apr 01 '17 at 03:06
  • { void printArray( const double list[],const int length){ for(int index=0; index – Nahom Desta Apr 01 '17 at 03:09
  • Are you joking? Please read https://stackoverflow.com/help/how-to-ask – javaLover Apr 01 '17 at 03:11
  • Why would I be joking? – Nahom Desta Apr 01 '17 at 03:13
  • 1
    @javaLover `[mcve]` prints and links the Minimal... message and `[ask]` does the same with how to ask – user4581301 Apr 01 '17 at 03:27
  • @user4581301 Ops! my bad, sorry. – javaLover Apr 01 '17 at 03:28
  • 1
    @javaLover Nothing to be sorry about. That's just to make your life easier. I think there's a bunch of them. I'd love to know more of those codes. – user4581301 Apr 01 '17 at 03:29
  • 2
    But getting back on topic, Nahom, pick a regular indentation pattern and you'll see the mistake almost immediately. – user4581301 Apr 01 '17 at 03:30
  • 1
    Actually, looking this over a bit more, you might not. It looks like you are trying to define functions inside functions. C++ doesn't allow this. May I recommend brushing up on your understanding of C++ syntax with [a good introductory book?](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) – user4581301 Apr 01 '17 at 03:34
  • @user4581301 just click on "Help" on the right of the comment box, then on "Learn more...", et voilà: http://stackoverflow.com/editing-help#comment-formatting – Fabio says Reinstate Monica Apr 03 '17 at 16:03
  • The code is formatted very poorly. Please [edit] your question and fix it! – Fabio says Reinstate Monica Apr 03 '17 at 16:06
  • Welcome to Stack Overflow! Please [edit] your code to reduce it to a [mcve] of your problem. Your current code includes much that is peripheral to your problem - a minimal sample normally looks similar to a good unit test: only performing one task, with input values specified for reproducibility. – Toby Speight Apr 03 '17 at 17:00
  • @FabioTurati hidden in plain sight. I feel a bit the fool now, but thank you very much. – user4581301 Apr 03 '17 at 17:51

1 Answers1

0

The code is fine until this part...

    getline(inFile, Name);
}

...marking the end of int main(), followed by...

{

...which is what the compiler is complaining about. This is neither the beginning of a function (no return type / identifier / parameter list), nor the beginning of a namespace (no namespace, no identifier), nor anything else that would make sense at this point. If this is to introduce a new block to main() and the } above was in error, then be told that you cannot define functions inside functions, as that would be what the next few lines do...

void printArray( const double list[],const int length){
for(int index=0; index<length; index++)
    cout << list[index] <<"  ";

   }

    void loadArray(fstream& in, double list[],const int length){

       for(int index=0; index<length; index++)
        in>>list[index];
}

...then followed by stand-alone code, which would indicate that you still consider yourself to be inside a function (main()?) as you cannot have code outside of functions...

cout <<"\n___________________________________________________________\n";
cout <<setw(6)<<"\nWEEK\t\t(ordered low to high -->)  ";

...followed by the beginning of another function definition...

void selectionSortAsc(double list[], int length){

...repeating the pattern of function-definition-apparently-inside-a-function-but-not-really-being-in-a-function a couple of times, followed by...

    }
return 0;

...noting the absence of a closing }, at which point I throw down my crystal ball in disgust and stop trying to figure out what you intended to do there.

DevSolar
  • 67,862
  • 21
  • 134
  • 209
  • Reformatting for easier readability done with [AStyle](http://astyle.sourceforge.net/), a tool I highly recommend for code sanitation before posting to the internet. – DevSolar Apr 03 '17 at 16:10
  • Also, get rid of all those global variables, they are bad for your health. ;-) – DevSolar Apr 03 '17 at 16:21