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
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
An Unofficial Cristiano Ronaldo Website : Ronaldo 7
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!!!
All the errors r in the file town.cpp .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
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
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.
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
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
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-town.cpp In constructor `Town::Town()':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; } } } }
-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
Remeber that your compiler is your friend. It will (usually) find the errors for you.
In Town constructor there is an illigal statement. You cant assign values to an array like thattown.cpp In constructor `Town::Town()':
You are confusing it with an initialization. Also you are writing past the last element which will corrupt memory(0...7 = valid index).Code:drugs[8] = {...........}
And for the other error its looks like there is a missing semicolon or something. E.i.
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.Code:drugs[i].changePrice("*", static_cast<float>(rand_between(80,120) / 100));
01000111011011110110111101100100 011101000110100001101001011011100110011101110011 01100100011011110110111001110100 01100011011011110110110101100101 01100101011000010111100101110011 0110100101101110 01101100011010010110011001100101
Good things donīt come easy in life!!!
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
umm...anyone out there?
An Unofficial Cristiano Ronaldo Website : Ronaldo 7
>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.
thx alot, i fixed everything!
An Unofficial Cristiano Ronaldo Website : Ronaldo 7