By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,300 Members | 1,789 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,300 IT Pros & Developers. It's quick & easy.

pet structure program

P: 91
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 displayKindAndName 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<iostream>
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 DisplayKindAndName(string[],int[]);

int main()

{

Pet information[6];
Pet Results;

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

GetInput(kind,name,age,gender,family,value);


return 0;
}
void GetInput(char&kind,char&Name,int&Age,char&Gender,c har&Family,double&Value)

{
cout<<"please enter the kind of the pet(e.g.Marmoset 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;
}
Sep 20 '07 #1
Share this Question
Share on Google+
3 Replies


kreagan
100+
P: 153
Expand|Select|Wrap|Line Numbers
  1. include<iostream>
  2. using namespace std;
  3. #include<string>
  4.  
  5. struct Pet{
  6.     string kind;
  7.     char name;
  8.     int age;
  9.     char gender;
  10.     char family;
  11.     double value;
  12. };
  13.  
  14.  
  15.   void GetInput(char&,char&,int&,char&,char&,double&);
  16.   void DisplayKindAndName(string[],int[]);
  17.  
  18.   int main()
  19.  
  20.   {
  21.  
  22.         Pet information[6];
  23.         Pet Results;
  24.  
  25.         Pet kind;
  26.         Pet name;
  27.         Pet age;
  28.         Pet gender;
  29.         Pet family;
  30.         Pet value;
  31.  
  32.        GetInput(kind,name,age,gender,family,value);
  33.  
  34.  
  35.       return 0;
  36.   }
  37.   void GetInput(char&kind,char&Name,int&Age,char&Gender,char&Family,double&Value)
  38.  
  39.   {
  40.        cout<<"please enter the kind of the pet(e.g.Marmoset monkey) \n";
  41.        cin>>kind;
  42.        cout<<"please enter the name of the pet(e.g.Penta)\n";
  43.        cin>>Name;
  44.        cout<<"Please enter the age of ther pet(e.g. 10 yrs)\n";
  45.        cin>>Age;
  46.        cout<<"Please may you enter the gender of the pet(M if male, F if female) \n";
  47.        cin>>Gender;
  48.        cout<<"Is that the Only pet of family (true or false) \n";
  49.        cin>>Family;
  50.        cout<<"What is the value of the pet?(e.g. R120.00)\n";
  51.        cin>>Value;
  52.   }
  53.  
What error are you getting?
Sep 20 '07 #2

rhitam30111985
100+
P: 112
u forgot to include a '#' in front of include<iostream>
Sep 20 '07 #3

kreagan
100+
P: 153
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.
Sep 20 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.