Advertisement
Guest User

Untitled

a guest
Jan 9th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.21 KB | None | 0 0
  1. #include <iostream>
  2. const int Max = 5;
  3.  
  4. int fill_array(double * begin, const double * end);
  5. void show_array(const double * begin, const double * end);
  6. void revalue(double r, double * begin, const double * end);
  7.  
  8. int main ()
  9. {
  10.     using namespace std;
  11.     double properties[Max];
  12.     int size = fill_array(properties, (properties + Max));
  13.     show_array(properties, (properties + size));
  14.     if (size > 0)
  15.     {
  16.         cout << "Enter revaluation factor: ";
  17.         double factor;
  18.             while (!(cin >> factor))
  19.         {
  20.             cin.clear ();
  21.             while (cin.get() != '\n')
  22.                 continue;
  23.             cout << "Bad input; Please enter a number: ";  
  24.         }
  25.         revalue(factor, properties, (properties + size));
  26.         show_array(properties, (properties + size));
  27.     }
  28.     cout << "Done.\n";
  29.     cin.get ();
  30.     cin.get ();
  31.     return 0;
  32. }
  33. int fill_array(double * begin, const double * end)
  34. {
  35.     using namespace std;
  36.     double temp;
  37.     int i;
  38.     for (double * pt = begin, i; pt != end ; pt++, i++)
  39.     {
  40.         cout << "Enter value #" << (i + 1) << ": ";
  41.         cin >> temp;
  42.         if (!cin)
  43.         {
  44.             cin.clear();
  45.             while (cin.get() != '\n')
  46.                 continue;
  47.             cout << "Bad input; input process terminated.\n";  
  48.             break;
  49.         }
  50.         else if (temp < 0)
  51.         {
  52.             break;
  53.         }
  54.         *pt = temp;
  55.     }
  56.     return i;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement