Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- double load_price()
- {
- double price;
- Goods * tempGd = new Goods();
- cin >> price;
- while (!cin)
- {
- cin.clear();
- #undef max
- std::cin.ignore(std::numeric_limits<std::streamsize>::max(), 'n');
- cout << endl;
- cout << "You didn't enter a number. Do so, please: ";
- cin >> price;
- } // endwhile
- if (!tempGd->set_price(price))
- {
- cout << endl;
- cout << "The price " << red << "must not" << white << " be negative." << endl;
- cout << "Please, insert a new price: ";
- load_price();
- }
- else
- {
- delete tempGd;
- return price;
- }
- }
- bool Goods::set_price(double price)
- {
- if (price> 0)
- {
- priceSingle_ = price;
- priceTotal_ = price* amount_;
- return true;
- }
- return false;
- }
- return load_price();
- #undef max
- double load_price()
- {
- for(;;) {
- double price;
- cin >> price;
- if (!cin)
- {
- cin.clear();
- std::cin.ignore(std::numeric_limits<std::streamsize>::max(), 'n');
- cout << endl;
- cout << "You didn't enter a number. Do so, please: ";
- continue;
- }
- if (!Goods().set_price(price))
- {
- cout << endl;
- cout << "The price " << red << "must not" << white << " be negative." << endl;
- cout << "Please, insert a new price: ";
- continue;
- }
- return price;
- }
- }
Add Comment
Please, Sign In to add comment