Really need help....

This is a discussion on Really need help.... within the C++ Programming forums, part of the General Programming Boards category; I 'm trying to write an ASCII clone of DopeWars, but had just gotten a bit of a break through, ...

  1. #1
    Registered User
    Join Date
    Nov 2003
    Posts
    66

    Really need help....

    I 'm trying to write an ASCII clone of DopeWars, but had just gotten a bit of a break through, when I found out there's a whole bunch of errors when compiling. Would somoene(s) please tell me wat i 've done wrong? Thx
    Attached Files Attached Files
    An Unofficial Cristiano Ronaldo Website : Ronaldo 7

  2. #2
    Veni Vidi Vice
    Join Date
    Aug 2001
    Posts
    343
    Why not post relavant code that causes the error? It sure would make it easier for us to help you. Also read this
    01000111011011110110111101100100 011101000110100001101001011011100110011101110011 01100100011011110110111001110100 01100011011011110110110101100101 01100101011000010111100101110011 0110100101101110 01101100011010010110011001100101
    Good things donīt come easy in life!!!

  3. #3
    Registered User
    Join Date
    Nov 2003
    Posts
    66
    Originally posted by ripper079
    Why not post relavant code that causes the error? It sure would make it easier for us to help you. Also read this
    All the errors r in the file town.cpp .
    The errors:

    Code:
    - In construtor Town::Town()
    - no matching function to call Drug::Drug()
    -candidates are: Drug:Drug(const Drug&)
                      Drug::Drug(std::basic_string < char,
    - line 41, parse error b4 { token
    - In member function void Town::refresh()
    - line 58 parse error b4 ',' token
    - line 62 pare error b4 ',' token
    - [build error][town.o] Error 1
    Last edited by Cris987; 02-27-2004 at 04:38 PM.
    An Unofficial Cristiano Ronaldo Website : Ronaldo 7

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Most of us won't bother to dowload a zipped file, extract the contents, and debug an unknown amount of code. Take what you have, shrink it down as much as possible so that it still gives you the errors and then post that code here along with a cut/paste of the exact errors you get, the compiler you use, and on what operating system.
    My best code is written with the delete key.

  5. #5
    Registered User
    Join Date
    Nov 2003
    Posts
    66
    well, I was on gamedev the other day, and saw a person get blast at for posting half a page of codes. He was advised to post up a zip file instead. so - ya. anyways, here's the code that has the errors:

    Code:
    //town.cpp
    #include "town.h"
    #include <iostream>
    #include <ctime>
    using namespace std;
    
    Drug::Drug(string Name, int Price, bool Avai)
    {
        name = Name;
        price = Price;
        avai = Avai;
    }
    
    void Drug::changeAvai()
    {
        avai = (avai? 0:1);    
    }
    
    void Drug::changePrice(char operand, double number)
    {
        switch(operand)
        {
           case 43:    // ascii number for ascii sign "+"
              price = static_cast<int>(static_cast<double>(price) + number);
              break;
           case 45:    // ascii number for ascii sign "-"      
              price = static_cast<int>(static_cast<double>(price) - number);
              break;
           case 42:    // ascii number for ascii sign "*"      
              price = static_cast<int>(static_cast<double>(price) * number);
              break;
           case 47:    // ascii number for ascii sign "/"
              price = static_cast<int>(static_cast<double>(price) / number);
              break;
           default:
              ; 
        }
    }    
    
    Town::Town()
    {    
        drugs[8] = {Drug("Acids", rand_between(800,1500), rand_between(1,8) < 4? 0 : 1),
                    Drug("Cocaines", rand_between(2000,10000), rand_between(1,8) < 4? 0 : 1),
                    Drug("Ectasies", rand_between(100,300), rand_between(1,8) < 4? 0 : 1),
                    Drug("PCPs", rand_between(1500,2200), rand_between(1,8) < 4? 0 : 1),
                    Drug("Heroins", rand_between(5000,12000), rand_between(1,8) < 4? 0 : 1),
                    Drug("Weeds", rand_between(400,1000), rand_between(1,8) < 4? 0 : 1),
                    Drug("Shrooms", rand_between(500,1200), rand_between(1,8) < 4? 0 : 1),
                    Drug("Speeds", rand_between(100,500), rand_between(1,8) < 4? 0 : 1)
                   };                //drugs have 3/8 chance of being not available
                                     //prices are randomize between a price range   
    }
    Code:
    #ifndef TOWN_H
    #define TOWN_H
    #include <string>
    #include <iostream>
    using namespace std;
    
    int rand_between(int min, int max);         //returns random number
    void cho_destin();          //prompts user to choose destination
    
    class Drug
    {
        public:
            Drug(string Name, int Price, bool Avai);        //constructor
            void changeAvai();                        //changes availability
            void changePrice(char operand, double number);        //changes price
                
        protected:
            string name;
            int price;
            bool avai;        //availabilty
    };
    
    class Town
    {
        public:
            Town();      //constructor        
            void refresh();         //refreshes each drug's price        
                    
        protected:               
            Drug drugs[8];        
    
    };    
    
    #endif
    Last edited by Cris987; 02-27-2004 at 05:08 PM.
    An Unofficial Cristiano Ronaldo Website : Ronaldo 7

  6. #6
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,161
    Cris:
    Originally posted by Prelude
    Most of us won't bother to dowload a zipped file, extract the contents, and debug an unknown amount of code. Take what you have, shrink it down as much as possible so that it still gives you the errors and then post that code here along with a cut/paste of the exact errors (the first 6 or so) you get, the compiler you use, and on what operating system. [/B]
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  7. #7
    Registered User
    Join Date
    Nov 2003
    Posts
    66
    kk, didn't have time in the morning, so didn't read thoroughly ><
    I use Dev C++, Windows XP . And here are the codes and errors:

    Code:
    //town.h
    #ifndef TOWN_H
    #define TOWN_H
    #include <string>
    #include <iostream>
    using namespace std;
    
    class Drug
    {
        public:
            Drug(string Name, int Price, bool Avai);        //constructor
            void changeAvai();                        //changes availability
            void changePrice(char operand, double number);        //changes price
                
        protected:
            string name;
            int price;
            bool avai;        //availabilty
    };
    
    class Town
    {
        public:
            Town();      //constructor        
            void refresh();         //refreshes each drug's price        
                    
        protected:               
            Drug drugs[8];        
    
    };    
    
    #endif
    Code:
    #include "town.h"
    #include <iostream>
    #include <ctime>
    using namespace std;
    
    Drug::Drug(string Name, int Price, bool Avai)
    {
        name = Name;
        price = Price;
        avai = Avai;
    }
    
    Town::Town()
    {    
        drugs[8] = {Drug("Acids", rand_between(800,1500), rand_between(1,8) < 4? 0 : 1),
                    Drug("Cocaines", rand_between(2000,10000), rand_between(1,8) < 4? 0 : 1),
                    Drug("Ectasies", rand_between(100,300), rand_between(1,8) < 4? 0 : 1),
                    Drug("PCPs", rand_between(1500,2200), rand_between(1,8) < 4? 0 : 1),
                    Drug("Heroins", rand_between(5000,12000), rand_between(1,8) < 4? 0 : 1),
                    Drug("Weeds", rand_between(400,1000), rand_between(1,8) < 4? 0 : 1),
                    Drug("Shrooms", rand_between(500,1200), rand_between(1,8) < 4? 0 : 1),
                    Drug("Speeds", rand_between(100,500), rand_between(1,8) < 4? 0 : 1)
                   };                //drugs have 3/8 chance of being not available
                                     //prices are randomize between a price range   
    }          
             
    void Town::refresh()
    {
        for(int i = 0; i < 8; i++)
        {
             //change price(increase/decrease) slightly - 80% to 120%
            drugs[i].changePrice("*", static_cast<float>(rand_between(80,120) / 100);          
            
            //3/8 chance of turning an available product to unavailable
            // or the other way around
            rand_between(1,8) < 4? drugs[i].changeAvai() : ;
            
            //1/4 chance of having a huge price drop or rise
            if (drugs[i].avai)
            {
               if (rand_between(0,1))
               {
                  drugs[i].changePrice(*, rand_between(2,4));   //price raise by 2 to 4 times           
                  cout << "The police just busted the "
                       << drugs[i].name
                       << " in town. Now, the prices are sky-high!"
                       << endl;
               }
               else
               {
                  drugs[i].changePrice(/, rand_between(2,4));   // price drop by 2 - 4 times
                  cout << "A large group of drugees has sent a bunch of "
                       << drugs[i].name
                       << " in town. Their prices are dropping like crazy!"
                       << endl;
               }
            }
        }
    }
    -town.cpp In constructor `Town::Town()':
    -line 14 town.cpp no matching function for call to `Drug::Drug()'
    -line 8 town.h candidates are: Drug::Drug(const Drug&)
    -line 7 town.cpp Drug::Drug(std::basic_string<char,
    -line 15 town.cpp parse error before `{' token
    -town.cpp In member function `void Town::refresh()':
    -line 32 town.cpp parse error before `;' token
    -line 36 town.cpp parse error before `;' token
    - Makefile.win [Build Error] [town.o] Error 1

    hope this helps....
    An Unofficial Cristiano Ronaldo Website : Ronaldo 7

  8. #8
    Veni Vidi Vice
    Join Date
    Aug 2001
    Posts
    343
    Remeber that your compiler is your friend. It will (usually) find the errors for you.
    town.cpp In constructor `Town::Town()':
    In Town constructor there is an illigal statement. You cant assign values to an array like that
    Code:
    drugs[8] = {...........}
    You are confusing it with an initialization. Also you are writing past the last element which will corrupt memory(0...7 = valid index).

    And for the other error its looks like there is a missing semicolon or something. E.i.
    Code:
    drugs[i].changePrice("*", static_cast<float>(rand_between(80,120) / 100));
    Try to fix thoose stuff at the moment and remember...if you get an compiler error read the error. Most times if you click on the error message the compiler will redirect you to the line that causes the error.
    01000111011011110110111101100100 011101000110100001101001011011100110011101110011 01100100011011110110111001110100 01100011011011110110110101100101 01100101011000010111100101110011 0110100101101110 01101100011010010110011001100101
    Good things donīt come easy in life!!!

  9. #9
    Registered User
    Join Date
    Nov 2003
    Posts
    66
    i did wat u told me, but the following errors still occur

    Code:
    -town.cpp In constructor `Town::Town()':
    -line 14 town.cpp no matching function for call to `Drug::Drug()'
    -line 8 town.h candidates are: Drug::Drug(const Drug&)
    -line 7 town.cpp Drug::Drug(std::basic_string<char,
    -line 15 town.cpp parse error before `{' token
    -town.cpp In member function `void Town::refresh()':
    -town.cpp  initializing argument 1 of `void Drug::changePrice(char, double)
    
    -line 36 town.cpp parse error before `;' token
    - Makefile.win [Build Error] [town.o] Error 1
    An Unofficial Cristiano Ronaldo Website : Ronaldo 7

  10. #10
    Registered User
    Join Date
    Nov 2003
    Posts
    66
    umm...anyone out there?
    An Unofficial Cristiano Ronaldo Website : Ronaldo 7

  11. #11
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >umm...anyone out there?
    They're probably afraid of your code. You have many syntax issues and one design issue that breaks encapsulation. The following compiles, but I had to add my own rand_between function and make Drug's protected members public because you access them directly in a member function of Town. I also had to declare a default constructor for Drug, which was one problem with your array. The second problem was that you can't initialize an array like you were trying to do because at that point it has already been initialized, you need to give each element more appropriate values individually:
    Code:
    #include <string>
    #include <iostream>
    using namespace std;
    
    int rand_between(int low, int high)
    {
      return high - low;
    }
    
    class Drug
    {
    public:
      Drug(): name(""), price(0), avai(false) {}
      Drug(string Name, int Price, bool Avai);        //constructor
      void changeAvai();                        //changes availability
      void changePrice(char operand, double number);        //changes price
    
    public:
      string name;
      int price;
      bool avai;        //availabilty
    };
    
    class Town
    {
    public:
      Town();      //constructor        
      void refresh();         //refreshes each drug's price        
    
    protected:               
      Drug drugs[8];        
    
    };
    
    #include <iostream>
    #include <ctime>
    using namespace std;
    
    Drug::Drug(string Name, int Price, bool Avai)
    {
      name = Name;
      price = Price;
      avai = Avai;
    }
    
    Town::Town()
    {
      //drugs have 3/8 chance of being not available
      //prices are randomize between a price range
      drugs[0] = Drug("Acids", rand_between(800,1500), rand_between(1,8) < 4);
      drugs[1] = Drug("Cocaines", rand_between(2000,10000), rand_between(1,8) < 4);
      drugs[2] = Drug("Ectasies", rand_between(100,300), rand_between(1,8) < 4);
      drugs[3] = Drug("PCPs", rand_between(1500,2200), rand_between(1,8) < 4);
      drugs[4] = Drug("Heroins", rand_between(5000,12000), rand_between(1,8) < 4);
      drugs[5] = Drug("Weeds", rand_between(400,1000), rand_between(1,8) < 4);
      drugs[6] = Drug("Shrooms", rand_between(500,1200), rand_between(1,8) < 4);
      drugs[7] = Drug("Speeds", rand_between(100,500), rand_between(1,8) < 4);
    }          
    
    void Town::refresh()
    {
      for(int i = 0; i < 8; i++)
      {
        //change price(increase/decrease) slightly - 80% to 120%
        drugs[i].changePrice('*', static_cast<float>(rand_between(80,120) / 100));          
    
        //3/8 chance of turning an available product to unavailable
        // or the other way around
        if (rand_between(1,8) < 4)
          drugs[i].changeAvai();
    
        //1/4 chance of having a huge price drop or rise
        if (drugs[i].avai)
        {
          if (rand_between(0,1))
          {
            drugs[i].changePrice('*', rand_between(2,4));   //price raise by 2 to 4 times           
            cout << "The police just busted the "
              << drugs[i].name
              << " in town. Now, the prices are sky-high!"
              << endl;
          }
          else
          {
            drugs[i].changePrice('/', rand_between(2,4));   // price drop by 2 - 4 times
            cout << "A large group of drugees has sent a bunch of "
              << drugs[i].name
              << " in town. Their prices are dropping like crazy!"
              << endl;
          }
        }
      }
    }
    My best code is written with the delete key.

  12. #12
    Registered User
    Join Date
    Nov 2003
    Posts
    66
    thx alot, i fixed everything!
    An Unofficial Cristiano Ronaldo Website : Ronaldo 7

Popular pages Recent additions subscribe to a feed

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