Hello,
I'm in the process of creating a dog simulation program to see what c++ I remember. I am having a problem, though. When my dog dies, I would like to it go back to the init function. I can do that fine but if I decide to choose exit after the dog dies, it does not quick the program. It continues on to the gamemenu function. I was wondering if anyone knew how I oculd fix this.
This code is a WIP and still needs to be organized better and finished. I only have the feeding part completed.
Code:
#include <iostream>
#include <string>
using namespace std;
int dHappiness = 10; //Dog Happiness Level
int dHunger = 10; //Dog Hunger Level
int dExercise = 10; //Dog Exercise Level
int dObedience = 10; //Dog Obedience Level
string dName = "Shermin"; //Dog Name
int main();
void init(); //Initilization Function
void begin(); //Begin the Simulation
void rename(); //Rename your Dog
void gamemenu(); //Main Game Menu
void feed();
void init()
{
int menuChoice = 0;
cout << "Welcome to the Dog Simulator v.1.0.\n";
cout << "Please Press:";
cout << "\n\n1) New Game";
cout << "\n2) Exit";
cout << "\n\nChoice: ";
cin >> menuChoice;
if (menuChoice == 1) //If New Game Goto Begin Func to Change Name
begin();
else if (menuChoice == 2 || dAlive != 1) { //If Exit Quit Sim
}
else {
cout << "Please choice 1 or 2."; //If None Retry
init();
}
}
void begin()
{
char changeName;
cout << "\n\n\n";
cout << "Welcome to TWIX's Dog Simulator. You have been left in charge of" << endl;
cout << "a friends dog named " << dName<<" and you have a bad memory. Would" << endl;
cout << "you like to rename the dog?";
cout << "\n\nChoice(Y/N): ";
cin >> changeName;
if (changeName == 'y') {
rename();
}
else if (changeName == 'n') {
gamemenu();
}
else {
cout << "Please enter the correct letter.";
begin();
}
}
void rename()
{
cout << "\n\nWhat would you like the dog to be named?";
cout << "\nName: ";
cin >> dName;
cout << "\n\nGreat! The dog will be named " << dName<< " until the owner returns.";
gamemenu();
}
void gamemenu()
{
int actionChoice;
do {
cout << "\n\n\nPlease use the menu below to interact with " << dName;
cout << "\n1)Feed";
cout << "\n2)Play";
cout << "\n3)Exercise";
cout << "\n4)Discipline " << dName;
cout << "\n5)Exit";
cout << "\n\nChoice: ";
cin >> actionChoice;
if (actionChoice == 1) {
feed();
}
else if (actionChoice == 2) {
//play();
}
else if (actionChoice == 3) {
//exercise();
}
else if (actionChoice == 4) {
//discipline();
}
else if (actionChoice == 5) {
}
else {
cout << actionChoice << " is not an choice.Please try again.";
}
} while(actionChoice != 5 );
}
void feed()
{
int foodChoice;
cout << "\n\nPlease choice a food type that you would like to feed " << dName;
cout << "\n1)Beef";
cout << "\n2)Chicken";
cout << "\n3)Vegetables";
cout << "\n4)Dry Dog Food";
cout << "\n5)Turkey";
cout << "\n6)Chocolate";
cout << "\n\nChoice: ";
cin >> foodChoice;
if (foodChoice == 1) {
cout << endl;
cout << dName << " loves beef.\n";
cout << dName << " gains +1 Hunger, +2 Happiness but, gets -1 Exercise.";
dHunger += 1;
dHappiness += 2;
dExercise -= 1;
}
else if (foodChoice == 2) {
cout << endl;
cout << dName << " enjoys his Chicken.\n";
cout << dName << " gains +3 Hunger, +1 Happiness but, loses 1 Excercise point.";
dHunger += 3;
dHappiness += 1;
dExercise -= 1;
}
else if (foodChoice == 3) {
cout << endl;
cout << "Vegetables make " << dName << " sick!\n";
cout << dName << " loses 3 Hunger points and loses 5 Happiness points.";
dHunger -= 3;
dHappiness -= 5;
}
else if (foodChoice == 4) {
cout << endl;
cout << dName << " loves dry dog food but it makes him thirsty.\n";
cout << dName << " keeps his current Hunger level.";
}
else if (foodChoice == 5) {
cout << endl;
cout << dName << " really likes turkey.\n";
cout << dName << " gains +2 Hunger, +3 Happiness and loses 2 exercise points.";
dHunger += 2;
dHappiness += 1;
dExercise -= 1;
}
else if (foodChoice == 6) {
cout << "You fed " << dName << " chocolate you idiot!\n";
cout << dName << " is now dead. Exiting simulation.\n\n\n";
init();
}
}
int main()
{
init();
return 0;
}
This forum kinda messed up the formatting a bit.