Thread: problam with initializer

  1. #1
    Registered User
    Join Date
    Oct 2012
    Posts
    7

    problam with initializer

    We did this program in class and i wanted see how will it run on CodeBlocks.But i got an error saying "expected initializer before 'void' on line 24".This is the first time i have this error.I try searching for a solution but didnt find one that will help me explain and figure out this problem.
    This is a problem
    Code:
    #include<iostream>
    #include<string>
    #include<fstream>
    #include<stdlib.h>
    using namespace std;
    const int N=50;
    const string name="koli.dat";
    
    struct kola{
    string kusha;
    string marka;
    int godina;
    double cena;
    fstream fp;
    };
    
    void add_kola();
    void reading (kola mas[],int &br);
    void output(kola mas[],int br);
    int  search(kola mas[],int br,string mar);
    void sort (kola  mas[],int br,string mar,int y);
    
    void menu()
    void main()
    
    {kola  car[N],int br(0);
    int ans;
    do{menu;
    do{cin>>ans;
    }while(a<1||a>6);
    
    switch(ans){
    case 1:add_kola();break;
    case 2:reading (car,br);break;
    case 3:output(car,br);break;
    case 4:if(tarsene(car,br,"Pego"))
            cout<<endl<<"Found";
            else
            cout<<endl<<"Not Found";
    case 5:sort(car,br,,"Pego",2008);break;
    case 6:cout<<endl<<"End";
    exit(1);
    }
    }while(ans!=6);
    }
    
    void add_kola()
    {kola k;
    cout<<endl<<"Add carshop";
    cin>>k.kusha;
    cout<<endl<<"Add marka";
    cin>>k.marka;
    cout<<endl<<"Add price";
    cin>>k.cena;
    fp.open(name,ios::binary;ios::app);
    if(fp.fail))
    {
    cout<<endl<<"Error";
    exit(0);
    }
    {
    fp.write((char*)&k,sizeof(kola))
    fp.close));
    }
    }
    
    void reading (kola mas[],int &br)
    {fp.open (name,ios::binary;ios::ate);
    br=fp.tellg()/sizeof(kola);
    fp.seeg(ol;ios::beg);
    fp.read(dae*) mas,br*sizeof(kola))l
    fp.close();
    }
    
    void output(kola mas[],int br)
    {for(i=0;i<br;i++)
    cout<"Carshop"<<mas.kusha[i].;
    cout<"Brand"<<mas.[i].marka;
    cout<"Year"<<mas.[i].godina;
    cout<"Price"<<mas.[i].cena;
    }
    
    int search(kola mas[];int br;string mar)
    {for (int i=0;i<br;i++)
    if (mas[i].marka=mar)
    return 1;
    return 0;
    }
    
    void sort(kola mas[];int br,string max,int y)
    {kola kk[N];int l(0);
    for(int i=0;i<br;i++)
    if(mas[i].mark=mar&&mas[i].godina==y)
    {kk[l]=mas[i];
    l++;
    }
    }

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Please indent your code properly, and watch out for semi-colons.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Oct 2012
    Posts
    7
    How about now ?Has the code become a little more easy to read(I need a second opinion)?
    Code:
    #include<iostream>
    #include<string>
    #include<fstream>
    #include<stdlib.h>
    using namespace std;
    const int N=50;
    const string name="koli.dat";
    
    struct kola{
        string kusha;
        string marka;
        int godina;
        double cena;
        fstream fp;
    };
    
    
    void add_kola();
    void reading (kola mas[],int &br);
    void output(kola mas[],int br);
    int  search(kola mas[],int br,string mar);
    void sort (kola  mas[],int br,string mar,int y);
    
    void menu()
    void main()
    
    {kola  car[N],int br(0);
    int ans;
        do{menu;
            do{cin>>ans;
            }
    }while(a<1||a>6);
    
    switch(ans){
            case 1:add_kola();break;
            case 2:reading (car,br);break;
            case 3:output(car,br);break;
            case 4:if(tarsene(car,br,"Pego"))
            cout<<endl<<"Found";
            else
            cout<<endl<<"Not Found";
            case 5:sort(car,br,,"Pego",2008);break;
            case 6:cout<<endl<<"End";
            exit(1);
            }
        while(ans!=6);
        }
    
    void add_kola()
    {kola k;
    cout<<endl<<"Add carshop";
    cin>>k.kusha;
    cout<<endl<<"Add marka";
    cin>>k.marka;
    cout<<endl<<"Add price";
    cin>>k.cena;
    fp.open(name,ios::binary;ios::app);
        if(fp.fail))
        {
        cout<<endl<<"Error";
        exit(0);
        }
           {
           fp.write((char*)&k,sizeof(kola))
           fp.close));
           }
    }
    
    
    void reading (kola mas[],int &br)
    {fp.open (name,ios::binary;ios::ate);
    br=fp.tellg()/sizeof(kola);
    fp.seeg(ol;ios::beg);
    fp.read(dae*) mas,br*sizeof(kola))l
    fp.close();
    }
    
    void output(kola mas[],int br)
    {for(i=0;i<br;i++)
    cout<"Carshop"<<mas.kusha[i].;
    cout<"Brand"<<mas.[i].marka;
    cout<"Year"<<mas.[i].godina;
    cout<"Price"<<mas.[i].cena;
    }
    
    int search(kola mas[],int br,string mar)
    {for (int i=0;i<br;i++)
        if (mas[i].marka=mar)
    return 1;
    return 0;
    }
    
    void sort(kola mas[],int br,string max,int y)
    {kola kk[N];int l(0);
       for(int i=0;i<br;i++)
        if(mas[i].mark=mar&&mas[i].godina==y)
            {kk[l]=mas[i];
            l++;
            }
    }

  4. #4
    Bored Programmer
    Join Date
    Jul 2009
    Location
    Tomball, TX
    Posts
    428
    You still didn't correct his second comment .. reread.

    and watch out for semi-colons
    and then look at your error

    expected initializer before 'void' on line 24
    and think what do initializer's end with?
    Virtual reality hello world http://www.rodneybrothers.com/vr/vrh...rld/index.html in html and javascript.
    Viewable with dodocase, google cardboard, OR, and other compatible VR gear.

  5. #5
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472
    and the indentation is not much improved sorry - don't write {code after braces for one thing
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    The best thing to do is adhere to some common style, such as Allman. This makes the code much easier to read.
    Your code's readability is improved, but I'm afraid it could be a lot better.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #7
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    This was clearly all written in one go without compiling along the way. That's not how to program. You need to do a little bit at a time, and compile often, especially when you're still a beginner.
    E.g A development process
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. hey . problam with my c code
    By natyshai in forum C Programming
    Replies: 7
    Last Post: 12-12-2011, 10:23 AM
  2. please any one can solve my pragma problam
    By nkrao123@gmail. in forum C Programming
    Replies: 5
    Last Post: 10-12-2009, 12:47 AM
  3. please solve my #pragma pack problam
    By nkrao123@gmail. in forum C Programming
    Replies: 2
    Last Post: 10-10-2009, 03:22 AM
  4. Problam with a global class variable
    By WebmasterMattD in forum C++ Programming
    Replies: 11
    Last Post: 01-21-2003, 04:38 AM
  5. initializer?
    By Luigi in forum C++ Programming
    Replies: 0
    Last Post: 11-29-2002, 12:31 PM