hi! I'm new in c++, can anyone give some instruction how I'll start this structure solution? if so, please give me some instruction
Define a structure called Toy with the following members:
. Name of Toy
. Price of Toy
. Made in (the place where the toy is made)
. Manufactured date (define as a structure with date, month, year)
Using the structure defined above, write a program that declares a variable of structure
Toy. Ask the user to enter the information of a toy. Then pass the variable to a function
to do the following:
. Check the manufactured date of the toy. If the date is before January 2012,
decrease 10% from the current price.
. Check the Made in information. If the toy is not made in Malaysia, then add
RM10.00 to the price.
Display the toy’s information in main(). Repeat for a new toy. Let the user chooses to
I hate to reiterate what Nathan already said but....what exactly are you stuck on?
Its hard to help you if you don't specify the problem.
Having said that I should point out that the above code already has mistakes -- did you know this?
e.g. line 16 should actually be: cout<<"Name of Toy:"<<to.toyName<<endl; -- toyname is not a member of your struct but toyName is
In main you also call display() when in fact you should be calling Display() (unless you rename your function).
Also, if you read the requirements that you posted you will notice that the manufacture date should be a struct, hence your toy struct should contain another struct instead of the three ints that you are currently using.
Where Date is defined as:
Finally, you don't appear to have any validation at present is this what you need help with?
I've updated a bit in the previous coding for date that you mentioned. Now I need to do the validation for( date and madein). (1) to decrease 10% of price if date before January 2012 (2) to add 10 Rm if the madein country is Malaysia. stuck again!
using namespace std;
void input (Toy & to)
cout<<"Enter The Toy Information:"<<endl;
cout<<"\n Enter Name of Toy: "; cin>>to.toyName;
cout<<" Enter Price of Toy: "; cin>>to.price;
cout<<" Enter made in Place: "; cin>>to.madeIn;
void input (Date & da)
cout<<"\nManufactured Date Info"<<endl;
cout<<" Enter Day: "; cin>>da.day;
cout<<" Enter Month: "; cin>>da.month;
cout<<" Enter Year: "; cin>>da.year;
void display (Toy to)
cout<<"\n Name of Toy: "<<to.toyName<<endl;
cout<<" Price of Toy: "<<"RM "<<to.price<<endl;
cout<<" Made In: "<<to.madeIn<<endl;
void Display (Date da)
cout<<"\nManufactured Date: "<<da.day <<"/"<<da.month<<"/"<<da.year<<"\n"<<endl;
int main ()
I would like to mention a couple of things akashi:
1) When programming you really need to pay close attention to code that you are reading or writing -- The updated code that you have provided shows a new struct that can be used to represent a date, however, your Toy struct still doesn't contain a data member.
It should look more like:
2) If you are struggling to figure out how to write something in code it can very often be helpful to write down a solution in pseudo-code or plain English first and then convert to code after.
Finally, just in case you weren't already aware, DaniWeb isn't a place you should come to get someone else to do your work for you - You will never learn this way!
Instead, the forumns provide a way for you to get assistance when you are having problems or to get new ideas that may further your development skills.
Once you have made an attempt at the validation, please post the code that you have produced yourself so that we can help you to resolve any issues.