I'm trying to create a program for a veterinary clinic. But I'm having some issues. It isn't calculating the total bill for the pet, and some of the menu options (and the menu itself) is an infinite loop, the program never ends.
Code:
//VetClinic.cpp
//Created/revised by <mcn29> on <12/3/10>
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
double totalBill = 0.0;
double vetVisit = 0.0;
double kennelService = 0.0;
int numOfDays = 0;
double totalKennel = 0.0;
double nailClipping = 0.0;
double bath = 0.0;
//delcare arrays
int BATH_TYPE[3] = {1, 2, 3};
double BATH_PRICE[3] = {30.00, 20.00, 15.00};
//function prototypes
void displayCatMenu();
void displayDogMenu();
double catBathOption();
double dogBathOption();
double vetOption();
double kennelOption();
double nailOption();
double calculateTotalBill();
int main()
{
//declare variables
string name = "";
string lastName = "";
int animalType = 0;
int option = 0;
double price = 0.0;
//get animal name and animal type
cout << "Animal First Name: ";
cin >> name;
cout << "Animal Last Name: ";
cin >> lastName;
cout << "Enter 1 for Cat or 2 for Dog: ";
cin >> animalType;
if (animalType == 1)
{
displayCatMenu();
cout << "Enter 1, 2, 3 or 4: ";
cin >> option;
}
while (option > 0 && option < 5)
{
displayCatMenu();
cout << "Enter 1, 2, 3 or 4: ";
cin >> option;
if (option == 1)
catBathOption();
if (option == 2)
vetOption();
if (option == 3)
kennelOption();
if (option == 4)
totalBill = bath + vetVisit + totalKennel + nailClipping;
cout << "Total Bill = $" << totalBill << endl;
}
//end while
//end if
if (animalType == 2)
{
displayDogMenu();
cout << "Enter 1, 2, 3, 4 or 5: ";
cin >> option;
}
while (option > 0 && option < 6)
{
if (option == 1)
dogBathOption();
if (option == 2)
vetOption();
if (option == 3)
kennelOption();
if (option == 4)
nailOption();
if (option == 5)
cout << "Total Bill = $" << totalBill << endl;
}//end while
//end if
if (option != 1 && option != 2)
cout << "Invalid Number" << endl;
//end if
system("pause");
return 0;
} //end of main function
//*****function definitions*****
void displayCatMenu()
{
cout << "1 Bath " << endl;
cout << "2 Vet Visit " << endl;
cout << "3 Kennel Service " << endl;
cout << "4 Total Bill " << endl;
} //end displayCatMenu
void displayDogMenu()
{
cout << "1 Bath " << endl;
cout << "2 Vet Visit " << endl;
cout << "3 Kennel Service " << endl;
cout << "4 Nail Clipping " << endl;
cout << "5 Total Bill " << endl;
} //end of displayDogMenu
double catBathOption()
{
double bath = 0.0;
int sub = 1;
bath = BATH_PRICE[2];
totalBill = totalBill + bath;
return bath;
}//end of catBathOption function
double dogBathOption()
{
double bath = 0.0;
int sub = 1;
cout << "Enter 1 for Large Dog or 2 for Small Dog: ";
cin >> bath;
if (bath == 1)
bath = BATH_PRICE[0];
else if (bath == 2)
bath = BATH_PRICE[1];
else if (bath < 0 && bath > 3)
cout << "Invalid Number" << endl;
totalBill = totalBill + bath;
return bath;
//end if
}//end of dogBathOption
double vetOption()
{
double vetVisit = 75.00;
totalBill = totalBill + vetVisit;
return vetVisit;
} //end of vetOption function
double kennelOption()
{
double kennelService = 30.00;
int numOfDays = 0;
double totalKennel = 0.0;
cout << "Enter Numer of Days in Kennel: ";
cin >> numOfDays;
totalKennel = (kennelService*numOfDays);
totalBill = totalBill + totalKennel;
return totalKennel;
} //end of kennelOption function
double nailOption()
{
double nailClipping = 8.0;
totalBill = totalBill + nailClipping;
return nailClipping;
} //end of nailOption function
double calculateTotalBill()
{
totalBill = bath + vetVisit + totalKennel + nailClipping;
return totalBill;
} //end calculateTotalBill function