Часть результата не выводится на экран. C++

Программа должна выводить на экран данные о транспорте, у которого одинаковое количество цилиндров. Проблема заключается в том, что когда я пытаюсь вывести таковые, то они не выводятся.

#include <iostream>
#include <string>
using namespace std;

#define MAX 10

class Cars
{
private:
    double MP, height, power;
    string diller;
public:
    string type;
    int PC;
    int c1;
    int c2;
    int c3;
    int c4;
    int c5;
    int c6;
    int c8;
    int cylinders;
    void getDetailsCar(void);
    void getDetailsTruck(void);
    void getDetailsBus(void);
    void printDetailsCar(void);
    void printDetailsTruck(void);
    void printDetailsBus(void);
    void CalculatingCylinders(void);
};
void Cars::getDetailsCar(void) {
    cout << "Enter diller of car: ";
    cin >> diller;
    cout << "Enter count of cylinders: ";
    cin >> cylinders;
    cout << "Enter mashine power: ";
    cin >> MP;
};

void Cars::getDetailsTruck(void) {
    cout << "Enter diller of truck: ";
    cin >> diller;
    cout << "Enter count of cylinders: ";
    cin >> cylinders;
    cout << "Enter lifting capacity of truck: ";
    cin >> height;

};
void Cars::getDetailsBus(void) {
    cout << "Enter diller of bus: ";
    cin >> diller;
    cout << "Enter count of cylinders: ";
    cin >> cylinders;
    cout << "Enter maxcount of passengers: ";
    cin >> PC;
};
void Cars::printDetailsCar(void) {
    cout << "Car info:\n";
    type = "car";
    cout << "Diller:" << diller << ", Type:" << type << ", Cylinders:" << cylinders << ", Power: " << power << endl;
}
void Cars::printDetailsTruck(void) {
    cout << "Figure info:\n";
    type = "truck";
    cout << "Diller:" << diller << ", Type:" << type << ", Cylinders:" << cylinders << ", Lifting capacity:" << height << endl;
}
void Cars::printDetailsBus(void) {
    cout << "Figure info:\n";
    type = "bus";
    cout << "Diller:" << diller << ", Type:" << type << ", Cylinders:" << cylinders << ", MaxCount of passengers:" << PC << endl;
}

void Cars::CalculatingCylinders(void) {
    if (c1 = 0, cylinders == 1) {
        c1 += 1;
    }
    if (c2 = 0, cylinders == 2) {
        c2 += 1;
    }
    if (c3 = 0, cylinders == 3) {
        c3 += 1;
    }
    if (c4 = 0, cylinders == 4) {
        c4 += 1;
    }
    if (c5 = 0, cylinders == 5) {
        c5 += 1;
    }
    if (c6 = 0, cylinders == 6) {
        c6 += 1;
    }
    if (c8 = 0, cylinders == 8) {
        c8 += 1;
    }
}

int main()
{

    Cars prd[MAX];
    Cars object_cars();
    int n, i, d;

    cout << "Enter total number of cars: ";
    cin >> n;

    for (i = 0; i < n; i++) {
        cout << "Enter info of car: " << i + 1 << ":\n";
        prd[i].getDetailsCar();
    };
    cout << endl;

    cout << "Enter total number of trucks: ";
    cin >> n;
    for (i = 0; i < n; i++) {
        cout << "Enter info of truck: " << i + 1 << ":\n";
        prd[i].getDetailsTruck();
    };
    cout << endl;

    cout << "Enter total number of buses: ";
    cin >> n;
    for (i = 0; i < n; i++) {
        cout << "Enter info of bus: " << i + 1 << ":\n";
        prd[i].getDetailsBus();
    }
    cout << endl;

    for (i = 0; i < n; i++) {
        cout << "Info of cars: " << (i + 1) << ":\n";
        prd[i].printDetailsCar();
    }
    for (i = 0; i < n; i++) {
        cout << "Info of Trucks: " << (i + 1) << ":\n";
        prd[i].printDetailsTruck();
    }
    for (i = 0; i < n; i++) {
        cout << "Info of Buses: " << (i + 1) << ":\n";
        prd[i].printDetailsBus();
    }
    cout << "Vehicle that have same count of cylinders: ";

И это вот здесь. Дальше результат не выводится. Почему?

    for (i = 0; i < n; i++) {
        if (prd[i].c1 > 1 and prd[i].c2 > 1 and prd[i].c3 > 1 and prd[i].c4 > 1 and prd[i].c5 > 1 and prd[i].c6 > 1 and prd[i].c8 > 1) {
            if (prd[i].type == "car") {
                cout << (i + 1) << ":\n";
                prd[i].printDetailsCar();
            }
            if (prd[i].type == "truck") {
                cout << (i + 1) << ":\n";
                prd[i].printDetailsTruck();
            }
        
            if (prd[i].type == "bus") {
                cout << (i + 1) << ":\n";
                prd[i].printDetailsBus();
            }
        }

    }

        return 0;
}

Ответы (1 шт):

Автор решения: Bogdan

Проблема не в выделенной части кода, а в значении переменной n. Раз уж решили делать общий массив для всех объектов, то по хорошему нужно держать отдельно кол-во машин каждого типа и отдельно общий размер массива. Примерно выглядит вот так:

int total = 0;
int carsCount, trucksCount;

cin >> carsCount;
total += carsCount;

// ... вводим инфо по Car

cin >> trucksCount;
total += trucksCount;

// ... вводим инфо по Truck
// с другими типами так же

И далее при обходе массива использовать переменную total:

for (int i = 0; i < total; i++) {
    // делаем что нужно
}

а в других циклах использовать счетчик, соответствующий типу:

for (int i = 0; i < carsCount; i++) {
    // print Cars
}

Неплохо было бы еще установить ограничения на вводимые значения переменных. Если ввести, скажем, по 5 единиц каждого типа, то можно получить сюрприз, т.к. элементов в общем массиве всего 10. Ну или создавать этот массив динамически в зависимости от введенных значений.

→ Ссылка