Like Tree2Likes
  • 2 Post By iMalc

problam with initializer

This is a discussion on problam with initializer within the C++ Programming forums, part of the General Programming Boards category; We did this program in class and i wanted see how will it run on CodeBlocks.But i got an error ...

  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
    21,457
    Please indent your code properly, and watch out for semi-colons.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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
    407
    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?

  5. #5
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,409
    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をこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,455
    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,296
    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
    Lesshardtofind and ivo93 like this.
    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, 09: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, 03:38 AM
  5. initializer?
    By Luigi in forum C++ Programming
    Replies: 0
    Last Post: 11-29-2002, 11:31 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21