Can I get the question's solution?

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
stop.

Dani AI

Generated

For : below is a compact, practical approach that fills the gaps left by the replies. 's reminder about showing an attempt is fair; a complete minimal example is provided so the core ideas (data layout, date comparison, price adjustment, input handling and repetition) are clear. was right that a loop is needed — a do/while loop is used in the sample.

Key points implemented in the sample:

  • A small Date struct and a lexicographic isBefore comparator to handle boundary checks reliably.
  • adjustPrice(Toy& t) modifies the toy in place (pass-by-reference) so main() can display the updated values.
  • Case-insensitive check for the origin string; std::getline and careful std::cin handling to avoid input issues.
  • Rounding to two decimals for currency display; for production code prefer integer cents to avoid floating-point pitfalls.
  • Simple input validation loops for numeric fields; the sample keeps validation minimal but shows the pattern.
#include <iostream>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <limits>

struct Date { int d, m, y; };
struct Toy  { std::string name; double price; std::string made_in; Date mfd; };

bool isBefore(const Date& a, const Date& b) {
    if (a.y != b.y) return a.y < b.y;
    if (a.m != b.m) return a.m < b.m;
    return a.d < b.d;
}

std::string toLower(std::string s) {
    std::transform(s.begin(), s.end(), s.begin(), [](unsigned char c){ return std::tolower(c); });
    return s;
}

void adjustPrice(Toy& t) {
    Date cutoff{1,1,2012}; // compare against boundary
    if (isBefore(t.mfd, cutoff)) t.price *= 0.90;
    if (toLower(t.made_in) != "malaysia") t.price += 10.0;
    t.price = std::round(t.price * 100.0) / 100.0;
}

// printToy and a main() loop are shown in the sample above pattern; input uses getline + numeric validation

Notes: treat the cutoff as strictly before 1-Jan-2012; validate months/days if needed (including leap years) for stronger correctness; for modern C++ projects consider std::chrono::year_month_day (C++20) for robust date handling.

Recommended Answers

All 2 Replies

Can I get the question's solution?

No, you won't receive any help until such time as you present code that demonstrates that you've made a genuine attempt to solve the problem.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.