pet structure program

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Nkhosinathie
    New Member
    • May 2007
    • 91

    pet structure program

    i've started doing structure today so i'm still not perfect to them.my lecturer has asked me to this program so i really need ur suggestions about it.

    The following information is available of each of 6 pets.

    Kind of pet ( for example Marmoset monkey)
    Name of pet (e.g Penta)
    Age of pet (e.g 10 yrs)
    Gender of pet (M if male, F if female)
    Only pet of family (true or false)
    Value of pet (e.g. R120.00)

    Task 1
    Write down the declaration for a struct containing the information of a single pet

    Task 2
    Write down the declaration of an array of 6 structs that will contain the information of 6 pets

    Task 3
    Write a function getInput which will input the information for 6 pets

    Task 4
    Write a function displayKindAndN ame which will display the kind and name of every pet of age 5 or above

    Task 5
    Write a main function to call the other two functions. Use the test data given below to run your program and submit printouts of the program and output.

    so i've done the first function and it is giving me an error that i can't figure out the problem about it.this is my code.


    [code=c++]
    include<iostrea m>
    using namespace std;
    #include<string >

    struct Pet{
    string kind;
    char name;
    int age;
    char gender;
    char family;
    double value;
    };


    void GetInput(char&, char&,int&,char &,char&,double& );
    void DisplayKindAndN ame(string[],int[]);

    int main()

    {

    Pet information[6];
    Pet Results;

    Pet kind;
    Pet name;
    Pet age;
    Pet gender;
    Pet family;
    Pet value;

    GetInput(kind,n ame,age,gender, family,value);


    return 0;
    }
    void GetInput(char&k ind,char&Name,i nt&Age,char&Gen der,char&Family ,double&Value)

    {
    cout<<"please enter the kind of the pet(e.g.Marmose t monkey) \n";
    cin>>kind;
    cout<<"please enter the name of the pet(e.g.Penta)\ n";
    cin>>Name;
    cout<<"Please enter the age of ther pet(e.g. 10 yrs)\n";
    cin>>Age;
    cout<<"Please may you enter the gender of the pet(M if male, F if female) \n";
    cin>>Gender;
    cout<<"Is that the Only pet of family (true or false) \n";
    cin>>Family;
    cout<<"What is the value of the pet?(e.g. R120.00)\n";
    cin>>Value;
    }
  • kreagan
    New Member
    • Aug 2007
    • 153

    #2
    Originally posted by Nkhosinathie
    [code=c]
    include<iostrea m>
    using namespace std;
    #include<string >

    struct Pet{
    string kind;
    char name;
    int age;
    char gender;
    char family;
    double value;
    };


    void GetInput(char&, char&,int&,char &,char&,double& );
    void DisplayKindAndN ame(string[],int[]);

    int main()

    {

    Pet information[6];
    Pet Results;

    Pet kind;
    Pet name;
    Pet age;
    Pet gender;
    Pet family;
    Pet value;

    GetInput(kind,n ame,age,gender, family,value);


    return 0;
    }
    void GetInput(char&k ind,char&Name,i nt&Age,char&Gen der,char&Family ,double&Value)

    {
    cout<<"please enter the kind of the pet(e.g.Marmose t monkey) \n";
    cin>>kind;
    cout<<"please enter the name of the pet(e.g.Penta)\ n";
    cin>>Name;
    cout<<"Please enter the age of ther pet(e.g. 10 yrs)\n";
    cin>>Age;
    cout<<"Please may you enter the gender of the pet(M if male, F if female) \n";
    cin>>Gender;
    cout<<"Is that the Only pet of family (true or false) \n";
    cin>>Family;
    cout<<"What is the value of the pet?(e.g. R120.00)\n";
    cin>>Value;
    }
    [/CODE]
    What error are you getting?

    Comment

    • rhitam30111985
      New Member
      • Aug 2007
      • 112

      #3
      u forgot to include a '#' in front of include<iostrea m>

      Comment

      • kreagan
        New Member
        • Aug 2007
        • 153

        #4
        Originally posted by kreagan
        What error are you getting?
        You have a problem with your getInput function and how you are calling it. The getInput function takes in an address to a character. Instead, you put in a structure of type Pet.

        Also, remember, the structure Pet describes your pet. So creating a variable name of type Pet doesn't make sense.

        Comment

        Working...