   Need lots of help with first game
  Below is the text based game I tried to create. I worked on it for hours trying to fix some of the errors, but I have no idea what is wrong. To me (I'm very new) it looks good. Could someone else try and compile it to help me see what I did wrong? Thanks for your help.~NewProgrammer081code//Maul the Duck; hardest program i've tried as of yet.#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:    int str = 100    int health = 20    int exp_given = 10    void Duck_Entrance();    void Duck_Leaves();}; class crit : public base_all{public:    srand(time(0));   int randomNumber = rand();   int hunger = (randomNumber % 10) + 1;   int boredom = hunger + 2    int str = 20 - hunger - boredom;    int health = 100    void Intro();    void Credits();    void Fight();    void Talk();    void Eat(int food = 5);    void Play(int happiness = 5);    void Stats();    int exp = 0   string criter_name;    private:    void PassTime(int time = 1);    };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();    if (crit.str => duck.health)   duck.health - crit.str;    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;    cout << "Attack Power: " << str;    cout << "Hunger: " << hunger;    cout << "Boredom: " << boredom;    cout << "Exp:" << exp << "/100";}    void crit::Eat(int food){    cout << "That was yummy.";    hunger -= food;    if (hunger < 0)   hunger = 0;    PassTime();}void crit::Play(int happiness){cout << "Done so soon?";    boredom -= happiness;    if (boredom < 0)   boredom = 0;    PassTime();}  int main(){    crit.Intro();    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();  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;   }/code[Edited by - NewProgrammer081 on December 9, 2005 11:26:01 AM]
  You need to provide a more complete description of your problem. Start with what the program is supposed to do. Then describe the problem you are having, under what conditions it occurs, and what you have tried to do to fix it. That will give us a starting point from which to help you.;  I like the above poster's words...But at just glancing at your code you are putting in code in the declaration space???Let me explain:A class have a public, private, and protected area.  It stores variables and functions.  When you say 'public' you are delcaring variables and functions that any functions/variable can see.  That is not a function...  though.  What you need is a constructor:class foo {//some class    public:   int foobar; // the delcaration   foo() { foobar = 5; } // the constructor};The constructor is the place to initialize and stuff.  The public area is to delcare...Anyways, please describe what you are having trouble with.  We will be able to help more, as just caying compile it and see what's wrong will not get everyone compiling your program and helping.Good luck!C++   ;Quote:Original post by Anonymous PosterI like the above poster's words...But at just glancing at your code you are putting in code in the declaration space???Let me explain:A class have a public, private, and protected area.  It stores variables and functions.  When you say 'public' you are delcaring variables and functions that any functions/variable can see.  That is not a function...  though.  What you need is a constructor:*** Source Snippet Removed ***The constructor is the place to initialize and stuff.  The public area is to delcare...Anyways, please describe what you are having trouble with.  We will be able to help more, as just caying compile it and see what's wrong will not get everyone compiling your program and helping.Good luck!C++What was I talking about???No offence at all...  But did you even read the beginning of the book?  You have so many common mistakes it looks to me like all you did was take the code out of the book and try to midify it...C++   ;Quote:Original post by NewProgrammer081Below is the text based game I tried to create. I worked on it for hours trying to fix some of the errors, but I have no idea what is wrong. To me (I'm very new) it looks good. Could someone else try and compile it to help me see what I did wrong? Thanks for your help.Instead of saying he made common mistakes why don't you help him huh?NewProgrammer081, I found two basic errors in your code, some missing ";" and the variables inside the object class declaration read my notes below.Hope it helps.~NewProgrammer081//Maul the Duck; hardest program i've tried as of yet.#include <iostream>#include <cstdlib>#include <ctime>#include <string>using namespace std;class base_all{public:    int str;    int health;    int exp_given;}; /*WRONGclass duck : public base_all {public:    you can't initialize the variable here, you must create a constructor, this is what you wrote, it's in a commentary, below is the correct way to do it.    int str = 100int health = 20    int exp_given = 10    void Duck_Entrance();    void Duck_Leaves();};*/// CORRECT belowclass duck : public base_all {public:    duck(); // the constructor    int str;int health;    int exp_given;    void Duck_Entrance();    void Duck_Leaves();};duck::duck(){    str = 100;  health = 20;    exp_given = 10;    // REMEMBER  THE ";"}  /*class crit : public base_all{public:    what happens here is the same, you mustn't initialize the variables here, correct way below.there are also some missing ";" here.  srand(time(0));   int randomNumber = rand();   int hunger = (randomNumber % 10) + 1;   int boredom = hunger + 2    int str = 20 - hunger - boredom;    int health = 100    void Intro();    void Credits();    void Fight();    void Talk();   I SUPPOSE you want it(eat, and play) to store these values right?But you can't just create a new variable insert it in the object like that, ur function for instance will create that variable and erase it when the function is over. So you must declare them in the object with a NULL value. And the function is wrong. The () space is for variables u want to send to the function and the { } is where the code is placed.    void Eat(int food = 5); void Play(int happiness = 5);    void Stats();    int exp = 0string criter_name;    private:    void PassTime(int time = 1);  << same mistake as eat and play here  };*/// CORRECT WAYclass crit : public base_all{public:    crit();   int food;    int happiness;    // << NEW VARIABLES, see u need to declare them here    int time;  int randomNumber;   int hunger;   int boredom;    int str; // AGAIN REMEMBER  THE ;    int health;    void Intro();    void Credits();    void Fight();    void Talk();    void Eat();   // << THAT's THE CORRECT FORM    void Play();    void Stats();    int exp;   string criter_name;    private:   void PassTime(){time = 1;};    };crit::crit(){    crit();    srand(time(0));   randomNumber = rand();   hunger = (randomNumber % 10) + 1;   boredom = hunger + 2;    str = 20 - hunger - boredom;    health = 100    food = 0;    happiness = 0;    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();    if (crit.str => duck.health)   duck.health - crit.str;    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(){    // I dunno if u want it, but i think u may want to add "<< endl;" or the stat text display will be messy.    cout << "HP: " << health;    cout << "Attack Power: " << str;    cout << "Hunger: " << hunger;    cout << "Boredom: " << boredom;    cout << "Exp:" << exp << "/100";}// WRONG WAY/*    void crit::Eat(int food){    cout << "That was yummy.";    hunger -= food;    if (hunger < 0)   hunger = 0;    PassTime();}void crit::Play(int happiness){cout << "Done so soon?";    boredom -= happiness;    if (boredom < 0)   boredom = 0;    PassTime();}*/// WHAT U WANT , well i think u want like thatvoid 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();    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();  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;   }Well, it took me a lot of time to look and correct it, I think it will run now, but I didn't test it. Remember the ";", and look carefully at the code changes so that u learn to do it correctly.Hope it works.Good luck,Victor Freire[Edited by - Alpha Nox on December 8, 2005 4:37:06 PM];  Code tags...Please?   ;  Oh, I forgot them. It's correct now.   ;  It may just be me or my browser but this thread is messed up...I have to scroll far to the right and stuff   ;  I dunno why I put the code tags (code and /code) and I didn't write any long lines. :/   ;Quote:Original post by Alpha NoxI dunno why I put the code tags (code and /code) and I didn't write any long lines. :/1. Use source tags (source and /source) for long source listings.2. Use manual line breaks on those extremely long in-source comments such as "you can't instantiate the variable here..."   