Filage

DynamicArr3

Mar 4th, 2024
702
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.12 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. void inputArray(int n, int* car, string what) {
  6.     cout << "Введите цены за " << what << " :\n";
  7.     for (int i = 0; i < n; i++) {
  8.         cout << i + 1 << what << " = ";
  9.         cin >> car[i];
  10.     }
  11. }
  12.  
  13. int averageSmth(int* car, int size, string what) {
  14.     int average = 0;
  15.     for (int i = 0; i < size; i++)
  16.         average += car[i];
  17.     average /= size;
  18.     cout << "Средняя цена марок " << what << ": " << average << endl;
  19.     return average;
  20. }
  21.  
  22. int main() {
  23.     setlocale(LC_ALL, "Russian");
  24.     int average_cars = 0, average_moto = 0, n, m;
  25.     cout << "Введите количество машин : ";
  26.     cin >> n;
  27.     int* car = new int[n];
  28.     inputArray(n, car, " машина ");
  29.     cout << "Введите количество мотоциклов : ";
  30.     cin >> m;
  31.     int* moto = new int[m];
  32.     inputArray(m, moto, " мотоцикл ");
  33.     average_cars = averageSmth(car, n, "машин");
  34.     average_moto = averageSmth(moto, m, "мотоциклов");
  35.     if (average_cars / average_moto > 3)
  36.         cout << "\nВерно";
  37.     else
  38.         cout << "\nНеверно";
  39.     delete[] car;
  40.     delete[] moto;
  41. }
  42.  
Advertisement
Add Comment
Please, Sign In to add comment