   Help
  Alright. My Program is a text based game that makes a creature and allows you to play with or feed the creature. Then, you get to try and fight a duck. Once you manage to hit level two, the game ends. (Will expand game after errors are all found out.) I'm very new and need the help. (I dont know how to make the code bubble thingy sorry.)//Maul the Duck; hardest program i've tried as of yet.//I have been working on my program for awhile and it hasn't been going so well.//Have tried to get help and fixed alot of noobish problems(i'm not very good yet) and now//it still wont work. Can you help Me?#include <iostream>#include <cstdlib>#include <ctime>#include <string>using namespace std;class base_all{public:    int str;    int health;    int exp_given;};class duck : public base_all {public:    duck();    int str;int health;    int exp_given;    void Duck_Entrance();    void Duck_Leaves();};duck::duck(){    str = 100;  health = 20;    exp_given = 10;}  class crit : public base_all{public:    crit();   int food;    int happiness;int time;  int randomNumber;   int hunger;   int boredom;    int str; int health;    void Intro();    void Credits();    void Fight();    void Talk();    void Eat();  void Play();    void Stats();    int exp;   string criter_name;    private:   void PassTime(){time = 1;};    };crit::crit(){    crit();    srand(time(0)); // main source of errors is this line.   randomNumber = rand();   hunger = (randomNumber % 10) + 1;   boredom = hunger + 2;    str = 20 - hunger - boredom;    health = 100    food = 5; // doesn't want to allow variable; says because of previous error    happiness = 5;    exp = 0;   time = 0;}void duck::Duck_Entrance(){    cout << "A ravaging duck with" << health << "appeared to fight you!";}void duck::Duck_Leaves(){    cout << "Duck ran away!";}void crit::Intro(){    cout << "I hope that you have fun with my first ever game!!!\n";    cout << "Please inform me of any errors that you may find.";}    void crit::Credits(){    cout << "Inspired by Critter Caretaker by: Micheal Dawson\n";    cout << "Congradulatioins on beating 'Maul The Duck'.\n";    cout << "Game Created By: Cody Linville.";}    void crit::Fight()(    cout << duck.Duck_Entrance(); //says it won't allow from previous errors    if (crit.str => duck.health)   duck.health - crit.str;//no clue why it wont allow this    else    crit.health - duck.str;   duck.Duck_Leaves();    if (crit.health = 0)   cout << "Game Over!!!";    if (duck.health = 0)   crit.exp + duck.exp_given;    if (crit.exp = 100)   crit.Credits();    if (crit.health || duck.health < 0)   crit.health || duck.health = 0;}    void crit::Talk(){    cout << "I'm your new pet. It's your job to name me and make me maul the duck.";    cout << "What should my name be?";    cin >> criter_name;}void crit::Stats(){    cout << "HP: " << health << endl;    cout << "Attack Power: " << str << endl;    cout << "Hunger: " << hunger << endl;    cout << "Boredom: " << boredom << endl;    cout << "Exp:" << exp << "/100" << endl;}void crit::Eat(){    cout << "That was yummy.";    hunger -= food;    if (hunger < 0)   hunger = 0;    PassTime();}void crit::Play(){cout << "Done so soon?";    boredom -= happiness;    if (boredom < 0)   boredom = 0;    PassTime();}  int main(){    crit.Intro(); //says i have an earlier error that wont allow this    crit.Talk();   int choice;    do{   cout << "What do you want to do with you creature?";   cout << "0 - Feed you pet.\n";   cout << "1 - Play with it.\n";   cout << "2 - Look at Critter stats.\n";   cout << "3 - Fight a creature.\n";   cout << "4 - Quit the game.\n";   cout << "Choice: ";   cin >> choice; switch (choice)   {   case 0:  crit.Eat(); // doesn't allow ANY of my functions calls before the break from here on down  break;   case 1:  crit.Play();  break;   case 2:  crit.Stats();  break;   case 3:  crit.Fight();  break;   case 4:  cout << "Too bad you have to go; I hope you had fun.\n";  break;   default:  cout << "\nSorry, but" << choice << "is not a valid one.\n";    }  } while (choice != 4); return 0;   }edit: added source tags -SiCrane   
Quote:Original post by NewProgrammer081(I dont know how to make the code bubble thingy sorry.)Check out the FAQ.As stated in my response to your previous post on this program, you need to tell us what isn't working. Just dumping a bunch of code and saying "It doesn't work. Can you help me?" doesn't help us help you.What does it do that it shouldn't do? Or what doesn't it do that it should do? Under what circumstances does the problem occur?;  Ok, basically, my compiler wont let it run. All of the errors are compiler errors that I don't know how to fix. The main error comes from the line where I try and make a random number. This problem causes the rest of the program to screw up and I can't figure it out. I just have no idea what I did wrong trying to make a random number.   ;  Could you post the error messages?;  Yes.... but can you tell us what are the exact error. Just copy past what you get as compile errors.   ;crit::crit(){    crit(); // <-- what is this good for ???Please try to delete the spurious invocation of the c'tor inside the c'tor. Perhaps it does not help to overcome the problem, but the line is good for nothing.   ;  Ok I had a test project opened so I did a compile:Changes1. you have to do what haegarr said2. srand(::time(0)); // main source of errors is this line.3. health = 100; // semicolon4. void crit::Fight(){ // wrong type here5. void Fight(duck &d); // in the crit class6.void crit::Fight(duck &d){    d.Duck_Entrance(); //says it won't allow from previous errors    if (str >= d.health)   d.health - str;//no clue why it wont allow this    else   health - d.str;   d.Duck_Leaves();    if (health = 0)   cout << "Game Over!!!";    if (health = 0)   exp + d.exp_given;    if (exp = 100)   Credits();    if (health < 0)   ;// crit died...    else if(d.health < 0)   ;//duck died...}7.int main(){    crit c;    duck d;    c.Intro(); //says i have an earlier error that wont allow this    c.Talk();    int choice;    do    {   cout << "What do you want to do with you creature?";   cout << "0 - Feed you pet.\n";   cout << "1 - Play with it.\n";   cout << "2 - Look at Critter stats.\n";   cout << "3 - Fight a creature.\n";   cout << "4 - Quit the game.\n";   cout << "Choice: ";   cin >> choice;   switch (choice)   {   case 0:  c.Eat(); // doesn't allow ANY of my functions calls before the break from here on down  break;   case 1:  c.Play();  break;   case 2:  c.Stats();  break;   case 3:  c.Fight(d);  break;   case 4:  cout << "Too bad you have to go; I hope you had fun.\n";  break;   default:  cout << "\nSorry, but" << choice << "is not a valid one.\n";   }   } while (choice != 4);   return 0;}Look at the changes and tell if there is anything you dont understandEDIT:Also, in your Fight function, d.health - str;//no clue why it wont allow thisis this supposed to bed.health -= str;//no clue why it wont allow this?[Edited by - pulpfist on December 15, 2005 10:22:09 AM];  I'll comment in some errors I see.class crit : public base_all{public:    // .... Skip this, it's fine    private:   void PassTime(){time = 1;};   // If you want to increment the time use time += 1 or time++};crit::crit(){// As somebody else said, you don't need this.......... or want it    crit(); // .... This is Good}    void crit::Fight(Duck &d)(    cout << d.Duck_Entrance();if (str => d.health) // Use >=   d.health - str   // Use d.health -= str    else{   health -= d.str;   d.Duck_Leaves();    }// Need these brackets, otherwise the duck will leave EVERY time    if (health = 0)  // When comparing, ALWAYS use ==, not =   cout << "Game Over!!!";    if (d.health = 0) // ==   exp + d.exp_given; // +=    if (exp = 100) // ==   Credits();    if (health || d.health < 0) // Not sure what this is supposed to do   health || d.health = 0; // ????}    I think that's all for now, that I saw in the minute I looked.Good luck.- Bnty_Hntr   ;  Compiler: Default compilerExecuting  g++.exe...g++.exe "C:\Documents and Settings\Student\My Documents\Help.cpp" -o "C:\Documents and Settings\Student\My Documents\Help.exe"    -I"C:\Dev-Cpp\include\c++"  -I"C:\Dev-Cpp\include\c++\mingw32"  -I"C:\Dev-Cpp\include\c++\backward"  -I"C:\Dev-Cpp\include"   -L"C:\Dev-Cpp\lib"C:/Documents and Settings/Student/My Documents/Help.cpp: In constructor    `crit::crit()':C:/Documents and Settings/Student/My Documents/Help.cpp:78: `this->crit::time'    cannot be used as a functionC:/Documents and Settings/Student/My Documents/Help.cpp:87: parse error before    `=' tokenC:/Documents and Settings/Student/My Documents/Help.cpp: At global scope:C:/Documents and Settings/Student/My Documents/Help.cpp:120: parse error before    `.' tokenC:/Documents and Settings/Student/My Documents/Help.cpp:122: `Fight' declared    as function returning a functionC:/Documents and Settings/Student/My Documents/Help.cpp:122: prototype for `int    crit::Fight()' does not match any in class `crit'C:/Documents and Settings/Student/My Documents/Help.cpp:61: candidate is: void    crit::Fight()C:/Documents and Settings/Student/My Documents/Help.cpp:122: `int crit::Fight()   ' and `void crit::Fight()' cannot be overloadedC:/Documents and Settings/Student/My Documents/Help.cpp: In function `int    main()':C:/Documents and Settings/Student/My Documents/Help.cpp:174: parse error before    `.' tokenC:/Documents and Settings/Student/My Documents/Help.cpp:192: parse error before    `.' tokenC:/Documents and Settings/Student/My Documents/Help.cpp:195: parse error before    `.' tokenC:/Documents and Settings/Student/My Documents/Help.cpp:198: parse error before    `.' tokenC:/Documents and Settings/Student/My Documents/Help.cpp:201: parse error before    `.' tokenC:/Documents and Settings/Student/My Documents/Help.cpp:187: confused by earlier errors, bailing outExecution terminatedsorry it took so long to post, im at school and the bell rang. Thanks for all the help.   ;#include <iostream>#include <cstdlib>#include <ctime>#include <string>using namespace std;class base_all{public:    int str;    int health;    int exp_given;};class duck : public base_all {public:    duck();    int str;int health;    int exp_given;    void Duck_Entrance();    void Duck_Leaves();};duck::duck(){    str = 100;  health = 20;    exp_given = 10;}  class crit : public base_all{public:    crit();   int food;    int happiness;int time;  int randomNumber;   int hunger;   int boredom;    int str; int health;    void Intro();    void Credits();    void Fight();    void Talk();    void Eat();  void Play();    void Stats();    int exp;   string criter_name;    private:   void PassTime(){time++;};    };crit::crit(){    srand(::time(0));   randomNumber = rand();   hunger = (randomNumber % 10) + 1;   boredom = hunger + 2;    str = 20 - hunger - boredom;    health = 100;    food = 5;happiness = 5;    exp = 0;   time = 0;}void duck::Duck_Entrance(){    cout << "A ravaging duck with" << health << "appeared to fight you!";}void duck::Duck_Leaves(){    cout << "Duck ran away!";}void crit::Intro(){    cout << "I hope that you have fun with my first ever game!!!\n";    cout << "Please inform me of any errors that you may find.";}    void crit::Credits(){    cout << "Inspired by Critter Caretaker by: Micheal Dawson\n";    cout << "Congradulatioins on beating 'Maul The Duck'.\n";    cout << "Game Created By: Cody Linville.";}    void crit::Fight(duck &d){    d.Duck_Entrance();if (str >= d.health)   d.health -= str;    else    {   health -= d.str;   d.Duck_Leaves();    }    if (health = 0)   cout << "Game Over!!!";    if (health == 0)   cout << "The duck died!";   exp + d.exp_given;    if (exp == 100)   Credits();    if (health < 0)   ;// crit died...    else if(d.health < 0)   ;//duck died...}    void crit::Talk(){    cout << "I'm your new pet. It's your job to name me and make me maul the duck.";    cout << "What should my name be?";    cin >> criter_name;}void crit::Stats(){    cout << "HP: " << health << endl;    cout << "Attack Power: " << str << endl;    cout << "Hunger: " << hunger << endl;    cout << "Boredom: " << boredom << endl;    cout << "Exp:" << exp << "/100" << endl;}void crit::Eat(){    cout << "That was yummy.";    hunger -= food;    if (hunger < 0)   hunger = 0;    PassTime();}void crit::Play(){cout << "Done so soon?";    boredom -= happiness;    if (boredom < 0)   boredom = 0;    PassTime();}  int main(){    crit c;    duck d;    c.Intro();c.Talk();    int choice;    do    {   cout << "What do you want to do with you creature?";   cout << "0 - Feed you pet.\n";   cout << "1 - Play with it.\n";   cout << "2 - Look at Critter stats.\n";   cout << "3 - Fight a creature.\n";   cout << "4 - Quit the game.\n";   cout << "Choice: ";   cin >> choice;   switch (choice)   {   case 0:  c.Eat();  break;   case 1:  c.Play();  break;   case 2:  c.Stats();  break;   case 3:  c.Fight(d);  break;   case 4:  cout << "Too bad you have to go; I hope you had fun.\n";  break;   default:  cout << "\nSorry, but" << choice << "is not a valid one.\n";   }   } while (choice != 4);   return 0;}I made the changes and my program came out as this. For some reason it still won't work. The thing I didn't understand about what you guys did was the d.health stuff. Don't you have to write out duck?Compilers errors:Compiler: Default compilerExecuting  g++.exe...g++.exe "C:\Documents and Settings\Student\My Documents\Help2.cpp" -o "C:\Documents and Settings\Student\My Documents\Help2.exe"    -I"C:\Dev-Cpp\include\c++"  -I"C:\Dev-Cpp\include\c++\mingw32"  -I"C:\Dev-Cpp\include\c++\backward"  -I"C:\Dev-Cpp\include"   -L"C:\Dev-Cpp\lib"C:/Documents and Settings/Student/My Documents/Help2.cpp:113: prototype for `   void crit::Fight(duck&)' does not match any in class `crit'C:/Documents and Settings/Student/My Documents/Help2.cpp:56: candidate is: void    crit::Fight()Execution terminatedSo what do you think I should do now?(Modifyed)   