daily pastebin goal
15%
SHARE
TWEET

Untitled

a guest Jan 24th, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. double load_price()
  2. {
  3.     double price;
  4.  
  5.     Goods * tempGd = new Goods();
  6.  
  7.     cin >> price;
  8.  
  9.     while (!cin)
  10.     {
  11.         cin.clear();
  12. #undef max
  13.         std::cin.ignore(std::numeric_limits<std::streamsize>::max(), 'n');
  14.         cout << endl;
  15.         cout << "You didn't enter a number. Do so, please: ";
  16.         cin >> price;
  17.     } // endwhile
  18.     if (!tempGd->set_price(price))
  19.     {
  20.         cout << endl;
  21.         cout << "The price " << red << "must not" << white << " be negative." << endl;
  22.         cout << "Please, insert a new price: ";
  23.         load_price();
  24.     }
  25.     else
  26.     {
  27.         delete tempGd;
  28.         return price;
  29.     }
  30. }
  31.    
  32. bool Goods::set_price(double price)
  33. {
  34.     if (price> 0)
  35.     {
  36.         priceSingle_ = price;
  37.         priceTotal_ = price* amount_;
  38.         return true;
  39.     }
  40.     return false;
  41. }
  42.    
  43. return load_price();
  44.    
  45. #undef max
  46. double load_price()
  47. {
  48.    for(;;) {
  49.       double price;
  50.       cin >> price;
  51.       if (!cin)
  52.       {
  53.          cin.clear();
  54.          std::cin.ignore(std::numeric_limits<std::streamsize>::max(), 'n');
  55.          cout << endl;
  56.          cout << "You didn't enter a number. Do so, please: ";
  57.          continue;
  58.       }
  59.       if (!Goods().set_price(price))
  60.       {
  61.          cout << endl;
  62.          cout << "The price " << red << "must not" << white << " be negative." << endl;
  63.          cout << "Please, insert a new price: ";
  64.          continue;
  65.       }
  66.       return price;
  67.    }
  68. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top