C++ structure Unhandled exception
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Thread: C++ structure Unhandled exception

Threaded View

  1. #1
    Join Date
    Sep 2012
    Posts
    5

    C++ structure Unhandled exception

    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.

    Code:
    #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;
    
    }
    Thank You
    Benjamin Betancourt
    Last edited by crazyben21; September 10th, 2012 at 02:48 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center