473,320 Members | 1,799 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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 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
3 2627
kreagan
153 100+
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
112 100+
u forgot to include a '#' in front of include<iostream>
Sep 20 '07 #3
kreagan
153 100+
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

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

Similar topics

5
by: kazack | last post by:
I am a little confused with code I am looking at. My c++ book does not go into passing a structure to a function so I pulled out a c book which does. and I do not understand the prototype verses...
0
by: Oliver Elphick | last post by:
The attached proposal is written primarily for Debian. Its motivation is that the current package upgrade process is pretty flaky and also that the current packaging does not really provide for...
5
by: brett valjalo | last post by:
Hey Gang! SORRY ABOUT THE LENGTH! Nice to see some of the same faces around this place from way back when ... Whatta buncha CDMA addicts some o' y'all are ;) Don't get me wrong, I...
11
by: Mannequin* | last post by:
Hi all, I'm working on a quick program to bring the Bible into memory from a text file. Anyway, I have three questions to ask. First, is my implementation of malloc () correct in the program to...
18
by: Anand Buddhdev | last post by:
Hi everyone, I'm a C newbie, so please be gentle. I have a program that defines the following things: typedef union { unsigned int I; unsigned char b; } dword;
7
by: Randy Yates | last post by:
Hi, I work in an embedded environment in which we often use a mix of C and assembly code. Thus a recurring requirement is to be able to take a C header file with structure definitions as input...
1
by: Robert S | last post by:
Hello group Since I want to modify a large program written in C(40K line) for the academic purposes and the program consists of several modules, it is necessary to have software structure in order...
3
by: chellappa | last post by:
Hi EveryBody! i need a information about creatting structure at runtime.... like example ..... int main() { char *a,*b; printf("Enter the structure"); scanf("%s",a); printf ("Enter The...
7
by: Jake Thompson | last post by:
Hello I created a DLL that has a function that is called from my main c program. In my exe I first get a a pointer to the address of the function by using GetProcAddress and on the dll side I...
5
by: zehra.mb | last post by:
Hi, I had written application for storing employee data in binary file and reading those data from binary file and display it in C language. But I face some issue with writing data to binary file....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.