Thread: Devcpp: parse error before ';' token

  1. #1
    Registered User
    Join Date
    Dec 2003
    Posts
    101

    Devcpp: parse error before ';' token

    I recently got Devcpp 5, for my xp. I have version 4 running on my 95, and this program compiles fine there.
    Allso, where can I get non-antique headers, so it stops telling me I'm using an antique one.
    Code:
    #include <iostream.h>
    
    int main()
    {
      cin >> int q; //Here!!!
    }
    ERRORS:
    Code:
    31 ...\Dev-Cpp\include\c++\backward\iostream.h
    In file included from .../Dev-Cpp/include/c++/backward/iostream.h
    
    1 ...\cppsource\Untitled1.cpp
                     from .../cppsource/Untitled1.cpp
    
    2 ...\Dev-Cpp\include\c++\backward\backward_warning.h:32
    #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <sstream> instead of the deprecated header <strstream.h>. To disable this warning use -Wno-deprecated.
    
     ...\cppsource\Untitled1.cpp
    [Warning] In function `int main()':
    
    5 ...\cppsource\Untitled1.cpp
    parse error before `;' token
    --

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > where can I get non-antique headers,
    It should already have them

    Try just
    #include <iostream>

    > cin >> int q; //Here!!!
    Try
    int q;
    cin >> q;
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    > cin >> int q; //Here!!!

    You have to declare q first:
    int q;
    cin >> q;

    And the new header is called <iostream>. So:
    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {
      int q;
      cin >> q;
    }
    Or here's how without including the whole namespace:
    Code:
    #include <iostream>
    
    int main()
    {
      int q;
      std::cin >> q;
    }

  4. #4
    Registered User
    Join Date
    Dec 2003
    Posts
    101
    O, ok That worked, thanks allot!
    --

  5. #5
    Registered User
    Join Date
    Dec 2003
    Posts
    101
    I don't see a need to create a new thread for this one so, I'l use this one. I decided to learn oop a few days ago, and for my first project I'm trying to make a duplicate of one of my structured programs. It compiles fine, and it does absolutely nothing. I added a loop - but.. any help?
    Code:
    #include <iostream>
    #include <stdlib.h>
    #include <time.h>
    using namespace std;
    
    class a
    {
          int q;
       public:
          a();
    };
    
    class m
    {
       protected:
          float pq[10], pau[10], pqq[10], pa[10], pd[10], pp[10], ps[10], pm[10]
                , pu[10], pbc[10], puc[10], pu1[10];
          int q, x, xx, xxx, t, w, a1, cccc, c2, cccr, r1, r2, ccc;
       public:
          m(int);
    };
    
    a::a()
    {
       system("CLS");
       cout <<"Turn based stratagy game (text) by 1veedo:       Release 11.22.3\n"
            <<"I hope to have computer operated oponents soon...\n"
            <<"Go back to  webpages.charter.net/all/project.htm  to check for later"
            <<"  releases.\n"
            <<"\nHow many players <=10: ";
       cin >> q;// none of that got displayed, the cin dosn't get executed...
       m a(q); //shold start the main part, dont think it gets executed eigther
    }
    
    
    m::m (int o)
    {
       q = o;
       t = o;
       ccc = 1;
       for (x=0;x<q;x++)
       {
          pa[x] = 0; //tech affence
          pd[x] = 0; //tech defence
          pp[x] = 200; //population
          ps[x] = 10;  //states
          pm[x] = 100; //money
          pu[x] = 20; //units
          pbc[x]=10; //unit cost
          puc[x]=40; //upgrade cost
       }
       
       do
       {
          t++;
          for (x=0; x<q; x++)
          {
             if (pp[x]==0)
                continue;
             r1= 1+rand() %5;
             r2= 1+rand() %5;
             pp[x] *=1+((r1*.75)/10.);
             if (ps[x]<=10)
                pm[x] += ps[x]*(pp[x]/100.);
             if (ps[x] <=7)
                pm[x] += (ps[x]*.7)*(pp[x]/100.);
             if (ps[x]>10 && ps[x] <15)
                pm[x] +=(ps[x]*.7)*(pp[x]/100.);
             else
                pm[x] += (ps[x]/2.1)*(pp[x]/100.);
             if (ps[x]>20)
                pm[x] -= (ps[x]/5)*(pp[x]/100.);
             puc[x] += (r1*2)-(r2*2);
             pbc[x] += (r1/2.)-(r2/2.);
    
             if (pbc[x]<5)
                pbc[x]+=4;
             if (pbc[x]>20)
                pbc[x]-=4;
    
             if (puc[x]<35)
                puc[x]+=10;
             if (puc[x]>80)
                puc[x]-=20;
          }
          
          for (x=0;x<q;x++)
          {
             if (pp[x]==0)
                continue;
             while(1)
             {
             //screen(t, x, q, xx, pq, pa, pd, pp, ps, pm, pu, pbc, puc);
    
             cin >> pq[x];
    
             if (pq[x] == 0)
                break;
    
             if (pq[x] == 1)
             {
             //   a(x, q, xxx, pq, pau, pa, pd, pp, ps, pm, pu, pu1, a1);
                continue;
             }
    
             if (pq[x] == 2)
             {
            //    bu(x, pqq, pp, ps, pm, pu, pbc);
                continue;
             }
             if (pq[x] == 3)
             {
             //   bt(x, pq, pa, pd, pm, puc);
                continue;
             }
             } //end while(1)
          } //end if
          cccc=0;
          for(c2=0; c2<q; c2++)
             if (pu[c2]>0)
                cccc++;
    
       }while(cccc>1);
       for(c2=0; c2<q; c2++)
          if(ps[c2]>0){
             w=c2+1;  break;}
    
       cout <<"Player "<<w<<" Wins!\n";
       t=0;
       cout <<"Play again?(1=yes)\n";
       cin >>ccc;
       if (ccc!=1)
          exit(1);
       a cc2();  
    }
    
    
    int main()
    {
       a cc1(); //it does nothing, not eaven displaying the text in it's constructor
       do{}while(1);
    }
    The original program "stra" is at my website. I'd add coments explaining everything, but my problem is in oop itself.
    Note: The game isn't operational if it did work, I just don't wan't to continue while it dosn't work to begin with.
    Last edited by 1veedo; 12-20-2003 at 08:44 AM.
    --

  6. #6
    Registered User
    Join Date
    Dec 2003
    Posts
    101

    Arrow This is the modified source

    LMAO
    Ok, I got it. I guess any sugestions are welcome, but - I've sucesfully made the programm look the same as the structured version, except it's oop. Well, here it is:
    Code:
    #include <iostream>
    #include <stdlib.h>
    #include <time.h>
    using namespace std;
    
    class m
    {
       protected:
          double pq[10], pau[10], pqq[10], pa[10], pd[10], pp[10], ps[10], pm[10]
                 , pu[10], pbc[10], puc[10], pu1, i, sd, aa[10][10][3]
                 , q, xxx, t, w, cccc, cccr, r1, r2, r3, ccc; //r1, r2 etc. = random
          int x, c2, xx, a1, g;
       public:
          m(int);
          int screen(); //main game screen
          int a(); //atack routine
          int bu(); //buy unuits
          int bt(); //buy technology
    };
    
    m::m (int o)
    {
       q = o; //holds how many players there are
       t = 0;
       ccc = 1;
       for (x=0;x<q;x++)//this sets the variables to the standard starting point
       {
          for(g=0;g<q;g++)
             aa[x][g][0] = 0; //tracks who atacks who
          pa[x] = 0; //tech affence
          pd[x] = 0; //tech defence
          pp[x] = 200; //population
          ps[x] = 10;  //states
          pm[x] = 100; //money
          pu[x] = 20; //units
          pbc[x]=10; //unit cost
          puc[x]=40; //upgrade cost
       }//x is used to signify which player is playing
       //this way the right arays get modified
       do
       {
          t++; //t keeps track of turns
          for (x=0; x<q; x++) //this for-loop changes the variables each time..
          {                  
             if (pp[x]==0)//if the player is dead, dont bother with the variables
                continue; 
             srand(time(0));
             r1= 1+rand() %5;
             r2= 1+rand() %5;
             pp[x] *=1+((r1*.75)/10.); //increas population
             if (ps[x]<=10)
                pm[x] += ps[x]*(pp[x]/100.); //monsy increases with the population
             if (ps[x] <=7)                 //and states
                pm[x] += (ps[x]*.7)*(pp[x]/100.);
             if (ps[x]>10 && ps[x] <15) 
                pm[x] +=(ps[x]*.7)*(pp[x]/100.);//if the player is powerful or week,
             else                              //the money changes inversly(power+=
                pm[x] += (ps[x]/2.1)*(pp[x]/100.);//less then the week+=more then
             if (ps[x]>20)                       //the strong) to level out the
                pm[x] -= (ps[x]/5)*(pp[x]/100.);//playing field
             puc[x] += (r1*2)-(r2*2);  //cost to buy units and tech. changes
             pbc[x] += (r1/2.)-(r2/2.);
    
             if (pbc[x]<5)//make sure the cost dosn't go out of bounds(too much or
                pbc[x]+=4;//too litle)
             if (pbc[x]>20)
                pbc[x]-=4;
    
             if (puc[x]<35)
                puc[x]+=10;
             if (puc[x]>80)
                puc[x]-=20;
          }
          
          for (x=0;x<q;x++)
          {
             if (pp[x]==0)
                continue;//if the player is dead, dont do his turn
             while(1)
             {
             screen();//displayes everything
    
             cin >> pq[x];//pq is the choice the user makes(it's an aray for farther
                         //developemnt, needed for later ideas)
             if (pq[x] == 0)
                break;//ends that players turn if(0)
    
             if (pq[x] == 1)
             {
             a();//atack routine
                continue;
             }
    
             if (pq[x] == 2)
             {
            bu();//buy units
                continue;
             }
             if (pq[x] == 3)
             {
             bt();//buy tech.
                continue;
             }
             } //end while(1)
          } //end if
          cccc=0;
          for(c2=0; c2<q; c2++)//to check if there are more then one player alive
             if (pu[c2]>0)
                cccc++;
    
       }while(cccc>1);
       for(c2=0; c2<q; c2++)//checks to see who won
          if(ps[c2]>0){
             w=c2+1;  break;}
    
       system("CLS");
       cout <<"Player "<<w<<" Wins!\n";
       t=0;
       cout <<"Play again?(1=yes)\n";
       cin >>ccc;
       if (ccc!=1)
          exit(1);
       //a cc2();  
    }
    
    int m::screen()  //main game sreen
    {
       system("CLS");
    
       cout <<"Player "<<x+1<<":   Turn"<<t<<endl
            <<"Money" <<pm[x] <<";  Pop."<<pp[x]<< ";  States"<<ps[x]
            <<";  Units"<< pu[x]<<endl
            <<endl<<"(1)Attack, (2)Buy units"
            <<"("<<pbc[x]<<")"<<", (3)Upgrade technology"<<"("<<puc[x]<<")"
            <<endl<<"Tech-afence: "<<pa[x]<<"  Tech-defence: "<<pd[x]
            <<endl<<endl;
    
       for (xx=0;xx<q;xx++)
       {
          if (pp[xx]>0)//if player isn't dead..
             cout <<"Player "<<xx+1<<"    States: "<<ps[xx]<<endl;
          else
             cout <<"Player "<<xx+1<<" is out\n";
       }
       cout <<endl;
       
       for(g=0;g<q;g++)
          if(aa[x][g][0] == 1){
             cout <<"Player "<<g+1<<" atacked with "<<aa[x][g][1]
                  <<" units\n";
             aa[x][g][0] = 0;}
    } 
    
    int m::a()  //atack routine
    {
       srand(time(0));
       r3= 1+rand() %10;
       r3/=10.;
    
       cout <<"How many units?"<<endl;
       sd=0; //used later, for deferance in units and states a1(player atacked) 
       cin >> pau[x];
    
       if (pau[x] > pu[x]-ps[x])
       {
          cout << "Not enough units to defend your states with"<<endl;
          system("PAUSE");
          return 0;
       }
    
       cout<<"Whom are you attacking? "<<endl;
       cin >>a1;
       a1-=1;//player being attacked
       if (ps[a1]==0)
       {
          cout <<"Player "<<a1+1<<" is out, can't attack.\n";
          system("PAUSE");
          return 0;
       }
       r3= 1+rand() %10;
       r3/=10.;//used for a random outcome(within boundries)
       if (r3=.5)
          r3=.7;
       if (r3<.5)
          r3*=2;
       if (r3<.5)
          r3*=2;
       if (r3<.5)
          r3*=2;
       if (r3 ==0)
          r3 = 1.;
       
       aa[a1][x][0] = 1;
       aa[a1][x][1] = pau[x];
       r3+=pa[x];
       r3-=pd[a1];
       pu[x] -=pau[x];
       pu[a1] -=pau[x]*r3;//less then 1 so the atacker has the disadvantage.
                         //unless he has tech. afence
                         //and tech defence for a1 is decresed from r3
       if (pu[a1]<ps[a1])//if(there are less units then states for a1)
       {                //atacker gets the deference.
          if (pu[a1]<=0){//incase the atacked is killed
             pu1=0;
             pu[x]+=pu[a1]*-1;}
          else
             pu1=pu[a1];
    
          sd=pu1-ps[a1];//gets the deference
          sd*=-1;
          aa[a1][x][2] = sd;
          if (ps[a1]/1.25<sd)//increases tech for the weeker ones
          {
             if (ps[a1]<=10)
                pd[a1]+=.05;
             if (ps[a1]/1.5<sd)
             {
                if (ps[a1]<=10)
                   pd[a1]+=.1;
                if (ps[x]<=10)
                   pa[x]+=.05;
             }
          }
          ps[x] += sd;//now the deference is added..
          ps[a1] -=sd;//and subtrakted from the atacked.
          if (pu[a1]<=10 && pu[a1]>0)//levels out the playing feild
          {
             //i=10-sd;
             pu[a1] +=10-ps[a1];
          }
       }
       if (pu[a1]<=0)//if dead.. set to 0
       {            //revolts etc. are calculated here
          pu[x]-=sd;
          if (sd<2)
             pu[x]-=sd;
          if (sd<1)
             pu[x] -=sd*2;
          if (sd>9)
             pu[x]-=sd*1.25;
          pm[x]+=pm[a1]/5.;
          pp[a1]=0;
          pu[a1]=0;
          pm[a1]=0;
          pa[a1]=0;
          pd[a1]=0;
       }
    }
    
    int m::bu()  //buy units
    {
       cout << "How manny?"<<endl;
       cin >> pqq[x];
    
       if (pqq[x]*pbc[x]>pm[x])
       {
          cout<<"Not enough money"<<endl;
          system("PAUSE");
          return 0;
       }
       if (pqq[x]*(pbc[x]/ps[x])>pp[x])
       {
          cout<<"Not enough people"<<endl;
          system("PAUSE");
          return 0;
       }
    
       pu[x] += pqq[x];
       pm[x] -=pqq[x]*pbc[x];//decreases money and populatin per state
       pp[x] -=pqq[x]*(pbc[x]/ps[x]);
    }
    
    int m::bt()
    {
       if (puc[x] > pm[x])
       {
          cout <<"Not enough money"<<endl;//a3
          system("PAUSE");
          return 0;
       }
       cout <<"Military: (1)Affence: "<<pa[x]<<", (2)Defence: "<<pd[x]<<endl;
       cin >>pq[x];
       if (pq[x] == 1){
          pa[x]+=.1; pm[x]-=puc[x];}
       if(pq[x]==2){
          pd[x]+=.1; pm[x]-=puc[x];}
    }
    
    
    int main()
    {
       do{
       system("CLS");
       cout <<"Turn based stratagy game (text) by 1veedo:       Release 12.20.3\n"
            <<"I hope to have computer operated oponents soon...\n"
            <<"Go back to  webpages.charter.net/all/project.htm  to check for later"
            <<"  releases.\n"
            <<"\nHow many players <=10: ";
       int q = 0;
       cin >> q;
       m a(q);
       }while(1);
    }
    I decided to take out the class 'a' and put it in the function 'main'. I don't think it's going to my website any time soon, because I need my dad to type the password for ftp
    Last edited by 1veedo; 12-20-2003 at 02:39 PM.
    --

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    You seriously need better names for all your variables and classes.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  8. #8
    Spaced Cadet
    Join Date
    Aug 2003
    Posts
    110
    Use a program that saves the ftp password, like smartftp or ws_ftp.

  9. #9
    Registered User
    Join Date
    Dec 2003
    Posts
    101
    I use ws_ftp, my dad won't let me check the little box.
    Originaly posted by Salem
    You seriously need better names for all your variables and classes.
    Ya, pa stands for player atack, pbc stands for player buy cost etc. I guess I could take out the p in everything but it seperates the variables with the player info from everything else. The class m stands for main...
    --

  10. #10
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >Ya, pa stands for player atack, pbc stands for player buy cost etc.
    And the reader of your code is supposed to know this how? Telepathy?

    >I guess I could take out the p in everything
    No, that would actually be a step backward. Your variables should be immediately obvious even if it means the names have to be longer than four letters.
    My best code is written with the delete key.

  11. #11
    Registered User
    Join Date
    Dec 2003
    Posts
    101
    I'll add coments explaining the existance of each variable.. I have for some, but not all.
    --

  12. #12
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    LOL - stop working on it for a day, then see how much sense you can still make of it.
    Stop working on it for a week, and it will be hopeless.

    Half the variables in your class have no business being there - like all those loop and question/answer variables.

    And all those x[10] are screaming for an array of the class, not an array within the class.

    Instead of
    myclass foo;

    It would be
    myclass foo[10];
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  13. #13
    Registered User
    Join Date
    Dec 2003
    Posts
    101
    I didn't look at the structured version for like 3 months, I used to be zornthrohacker(I quit posted when I stoped programming - now I'm back!)

    >Half the variables in your class have no business being there - like all those loop and question/answer variables.
    I'll get to that eventually...

    >And all those x[10] are screaming for an array of the class, not an array within the class. ...

    What do you meen
    --

  14. #14
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >I'll add coments explaining the existance of each variable..
    Why use a comment at just the declaration when your code can do it everywhere? If I gave you code and didn't tell you what it did, what would your reaction be if all of my variables looked like these:

    double pq[10], pau[10], pqq[10], pa[10], pd[10], pp[10], ps[10], pm[10], pu[10], pbc[10], puc[10], pu1, i, sd, q, xxx, t, w, cccc, cccr, r1, r2, r3, ccc;
    int x, c2, xx, a1

    I would bet my next paycheck that you would not be happy, and would probably become violent. My reaction has been similar in the past.

    >What do you meen
    An array of objects, not an object of arrays.
    My best code is written with the delete key.

  15. #15
    Registered User
    Join Date
    Dec 2003
    Posts
    101
    The old version at my website (the one that dosn't work) explains what everythings doing. I'll go back through and add them to the oop version... EDIT: Done!

    Btw, as I modify the program, I'm editing the newer post with the working version(above with an arow).
    Last edited by 1veedo; 12-20-2003 at 12:52 PM.
    --

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 10:33 AM
  2. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  3. C++ compilation issues
    By Rupan in forum C++ Programming
    Replies: 1
    Last Post: 08-22-2005, 05:45 AM
  4. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  5. Parsing and Tokens (strtok)
    By readerwhiz in forum C Programming
    Replies: 6
    Last Post: 04-22-2002, 09:57 AM