V(ery) Basic
Aug 21st, 2000, 03:37 PM
At one point there were 71 errors on this code *smiles defiantly* , but now there are only 5. They are all in the switch 'bit'. Can somebody tell me what is wrong because I've looked at the book and I think I've put all the ; 's in the right places and stuff:
#include <iostream.h>
void ShowMenu();
class Dog
{
public:
void GiveTreat(unsigned int Quantity);
void Sleep(unsigned int Hours);
void Exercise(unsigned int Minutes);
int GetHealth() ;
int GetHunger() ;
int GetAge() ;
int GetHappiness() ;
void Bark() ;
void WagTail() ;
private:
int Health;
int Hunger;
int Age;
int Happiness;
};
void Dog::Bark()
{
cout << "Woof! Woof!\n";
}
void Dog::WagTail()
{
cout << "Waggy tail!\n";
}
void Dog::GiveTreat(unsigned int Quantity)
{
cout << "Eaten Treat!\n";
for(; Quantity != 0; Quantity--)
{
this->WagTail();
}
this->Happiness += Quantity;
this->Hunger -= Quantity;
if ((Quantity <= 9) && (Quantity > 1))
{
this->Health = this->Health + 5;
}
else
{
this->Health -= 1;
this->Happiness -= 5;
this->Bark();
}
}
void Dog::Sleep(unsigned int Hours)
{
cout << "Woken up\n";
static Slept;
this->Bark();
this->WagTail();
this->WagTail();
this->Health += 2;
this->Happiness += 2;
this->Hunger += 3;
if (this->Hunger >= 7)
{
this->Bark();
}
Slept += Hours;
if (Slept > 100)
{
Slept = 0;
this->Age += 1;
}
}
void Dog::Exercise(unsigned int Minutes)
{
cout << "Exercise over\n";
this->WagTail();
this->Bark();
this->WagTail();
this->Sleep(Minutes*50);
this->Happiness += 2;
this->Hunger += 1;
this->Health += 3;
}
int Dog::GetAge()
{
return this->Age;
}
int Dog::GetHealth()
{
return this->Health;
}
int Dog::GetHunger()
{
return this->Hunger;
}
int Dog::GetHappiness()
{
return this->Happiness;
}
int main()
{
unsigned int Action, Quant, EXIT_CON = 4;
Dog Aspen;
do
{
ShowMenu();
cin >> Action;
switch Action
{
case 1:
{
cout << "Please enter hours spent exercising";
cin >> Quant;
Aspen.Exercise(Quant);
break;
}
case 2:
{
cout << "Please enter how many treats you gave the dog";
cin >> Quant;
Aspen.GiveTreat(Quant);
break;
}
case 3:
{
Quant = Aspen.GetHealth() - Aspen.GetHunger();
Aspen.Sleep(Quant);
break;
}
}
} while (Action != EXIT_CON);
return 0;
}
void ShowMenu()
{
cout << " Menu \n";
cout << "(1) Exercise \n";
cout << "(2) Give Treat\n";
cout << "(3) Sleep\n";
cout << "(4) Exit\n";
}
(Aspen's the name of our puppy)
This is supposed to be a bit of a Tamigochi (or however you spell it) app. This is the first time I've used a class in C++, so I thought this might be a good place to start. I know that a lot of tweaking has to be done to some of the numbers abd a few more properties and functions have to be added, but I can't really work this out until I have actually run the ****ing thing.
Thank you very much.
(PS: This is a C++ (not VC++) app, so put it in a 'C++ source file' if you have VC++ (and sorry if that sounds patronising, but one of you suckers <ahem> wonderful people must not know) )
#include <iostream.h>
void ShowMenu();
class Dog
{
public:
void GiveTreat(unsigned int Quantity);
void Sleep(unsigned int Hours);
void Exercise(unsigned int Minutes);
int GetHealth() ;
int GetHunger() ;
int GetAge() ;
int GetHappiness() ;
void Bark() ;
void WagTail() ;
private:
int Health;
int Hunger;
int Age;
int Happiness;
};
void Dog::Bark()
{
cout << "Woof! Woof!\n";
}
void Dog::WagTail()
{
cout << "Waggy tail!\n";
}
void Dog::GiveTreat(unsigned int Quantity)
{
cout << "Eaten Treat!\n";
for(; Quantity != 0; Quantity--)
{
this->WagTail();
}
this->Happiness += Quantity;
this->Hunger -= Quantity;
if ((Quantity <= 9) && (Quantity > 1))
{
this->Health = this->Health + 5;
}
else
{
this->Health -= 1;
this->Happiness -= 5;
this->Bark();
}
}
void Dog::Sleep(unsigned int Hours)
{
cout << "Woken up\n";
static Slept;
this->Bark();
this->WagTail();
this->WagTail();
this->Health += 2;
this->Happiness += 2;
this->Hunger += 3;
if (this->Hunger >= 7)
{
this->Bark();
}
Slept += Hours;
if (Slept > 100)
{
Slept = 0;
this->Age += 1;
}
}
void Dog::Exercise(unsigned int Minutes)
{
cout << "Exercise over\n";
this->WagTail();
this->Bark();
this->WagTail();
this->Sleep(Minutes*50);
this->Happiness += 2;
this->Hunger += 1;
this->Health += 3;
}
int Dog::GetAge()
{
return this->Age;
}
int Dog::GetHealth()
{
return this->Health;
}
int Dog::GetHunger()
{
return this->Hunger;
}
int Dog::GetHappiness()
{
return this->Happiness;
}
int main()
{
unsigned int Action, Quant, EXIT_CON = 4;
Dog Aspen;
do
{
ShowMenu();
cin >> Action;
switch Action
{
case 1:
{
cout << "Please enter hours spent exercising";
cin >> Quant;
Aspen.Exercise(Quant);
break;
}
case 2:
{
cout << "Please enter how many treats you gave the dog";
cin >> Quant;
Aspen.GiveTreat(Quant);
break;
}
case 3:
{
Quant = Aspen.GetHealth() - Aspen.GetHunger();
Aspen.Sleep(Quant);
break;
}
}
} while (Action != EXIT_CON);
return 0;
}
void ShowMenu()
{
cout << " Menu \n";
cout << "(1) Exercise \n";
cout << "(2) Give Treat\n";
cout << "(3) Sleep\n";
cout << "(4) Exit\n";
}
(Aspen's the name of our puppy)
This is supposed to be a bit of a Tamigochi (or however you spell it) app. This is the first time I've used a class in C++, so I thought this might be a good place to start. I know that a lot of tweaking has to be done to some of the numbers abd a few more properties and functions have to be added, but I can't really work this out until I have actually run the ****ing thing.
Thank you very much.
(PS: This is a C++ (not VC++) app, so put it in a 'C++ source file' if you have VC++ (and sorry if that sounds patronising, but one of you suckers <ahem> wonderful people must not know) )