Hi guys.
I'm getting Unhandled exception when try to run option 3.
I don't know what I'm doing wrong. Any help will be greatly appreciated. Right now my teacher is not on vector subject. This my code below.
Thank YouCode:#include <iostream> #include <string> using namespace std; struct Vet { string name; int numOfAnimals; string phoneNum; }; struct CustomerAnimal { int anID; string name; double weight; char agrressive; string species; }; //(*p) is the same as p-> //(*p).agrressive or p->agrressive is pointing to the CustomerAnimal type //gets the pet information void getPetInfo(CustomerAnimal *p, int count = 1) { cout << "Pet number " << count <<": "<<endl; cout << "What is the pet ID number? "; cin >> p->anID; cout << "What is your pet name? "; cin.ignore(); getline(cin, p->name); cout << "What is the weight of your pet? "; cin >> p->weight; while (p->agrressive != 'y' && p->agrressive != 'n') { cout << "Is your pet aggressive? (y/n)"; cin >> p->agrressive; } cout << "What is your pet species?"; cin.ignore(); getline(cin, p->species); cout << endl; } //display the pet information void displayPetInfo(CustomerAnimal *p) { cout << "Pet ID" << " " << "Pet Name" <<" " << "Pet Weight" << "Pet Aggressive" << " " << "Pet Species " << endl; cout << p->anID << " " << p->name << " " << p->weight << " " << p->agrressive << " " << p->species << endl; } //get the vet information void getVetInfo(Vet &d) { cout << "What is the name of the veterinary physician working on the pet? "; cin.ignore(); getline(cin, d.name); cout << "What is the veterinary physician emergency number? "; cin.ignore(); getline(cin, d.phoneNum); cout << endl; } int main() { CustomerAnimal *pet; Vet animalDoc; int menuOption = -1; int count; cout << "Hi and welcome to Benjamin's animal clinic.\n" << endl; cout << "Before we take in your pet in, you must first check in and provide us with the folowing informarion.\n" << endl; cout << "How many pets are you bringing in today? "; cin >> animalDoc.numOfAnimals; getVetInfo(animalDoc); pet = new CustomerAnimal[animalDoc.numOfAnimals]; while (menuOption != 5) { cout << "1. Please enter your pet/s information." << endl; cout << "2. Change your veterinary physician." << endl; cout << "3. List Vet and Pet information." << endl; cout << "4. Quit." << endl; cin >> menuOption; switch (menuOption) { case 1: for (count = 0; count < animalDoc.numOfAnimals; count++) { int petNum = count + 1; getPetInfo(pet, petNum); pet++; } break; case 2: getVetInfo(animalDoc); break; case 3: /* for (count = 0; count < animalDoc.numOfAnimals; count++) { displayPetInfo(pet); } */ //Just for testing purposes //Top commented out code give the same runtime error // Top Code I can't figure out how to cycle through the array to show the result. cout << endl << pet[0].name << pet[1].name << endl; break; default: break; } } delete [] pet; system("pause"); return 0; }
Benjamin Betancourt


Reply With Quote
Bookmarks