Decided to take out the exception throwing...we didn't have to have that anyway. Still getting a couple errors that I'm not understanding though. Says that local function definitions are illegal...where do I put them then? Sorry to sound so dumb. Still not very experienced in this. Any help would be appreciated.
Code:
#ifndef H_Dog
#define H_Dog
#include <iostream>
using namespace std;
class Dog //Dog class
{
public:
static int licenseFee;
//static variable for license fee
char dName;
char dBreed;
int dAge;
char answer;
void Dog::setDogInfo(char dName, char dBreed, int dAge);
//Function prototype to set dog's name, age, and breed
//Postcondition: dogName=dName dogBreed=dBreed dogAge=dAge
void Dog::printDogInfo() const;
//Function to print "Your dog's name is dogName. The dog's breed
//is dogBreed. Age is dogAge years. The license fee is $12.25."
private:
char dogName;
char dogBreed;
int dogAge;
};
void Dog::setDogInfo(char dName, char dBreed, int dAge)
//Function to enter dog's name, breed, and age
{
cout << "Please enter your dog's name and press enter: ";
cin >> dName;
cout << endl;
cout << "Please enter your dog's breed and press enter: ";
cin >> dBreed;
cout << endl;
cout << "Please enter your dog's age in years and press enter: ";
cin >> dAge;
cout << endl;
cout << "Your dog's name is " << dName << ". The dog's breed is "
<< dBreed << ". Age is " << dAge << " years. " << endl;
dogName = dName;
dogBreed = dBreed;
dogAge = dAge;
}
void Dog::printDogInfo() const //Function to print dog's name, age, breed, license fee
{
cout << "Your dog's name is " << dogName << ". The dog's breed is "
<< dogBreed << ". Age is " << dogAge << " years."
<< "The license fee is $" << licenseFee << "." << endl;
}
#endif
main.cpp:
Code:
#include <iostream>
#include <string>
#include "Dog.h"
using namespace std;
void displayMenu(); //Function prototype to display main menu
int main()
{
bool done = false; //variable for menu choice selection verification
int choice = 0; //variable to hold menu choice
double Dog::licenseFee = 12.25; //static variable declaration for license fee
string str = "Please enter again."; //string variable to hold error message
char Dog::dName = "Rex";
char Dog::dBreed = "Beagle";
int Dog::dAge = 5;
displayMenu();
do
{
try
{
cin >> choice;
if (choice < 1 || choice > 3)
throw str;
done = true;
}
catch (string messageStr)
{
cout << messageStr << endl;
cin.clear();
cin.ignore(100, '\n');
}
}
while (!done);
if (choice == 1)
{
Dog::setDogInfo();
}
else
if (choice == 2)
{
Dog::printDogInfo();
}
else
if (choice == 3)
{
system("cls");
}
system ("pause");
return 0;
}
void displayMenu() //Function to display main menu
{
cout << "Welcome to the Dog Program" << endl;
cout << "Please enter the number of your selection" << endl;
cout << "1) Enter dog information" << endl;
cout << "2) Print dog information" << endl;
cout << "3) Exit the program" << endl;
}