Помогите с задачей плиз. Пользователь вводит данные пока не скажет хватит. Затем по выбору пользователя программа показывает данные выше или ниже указанного порога или данные по указанной модели (это вообще не понимаю как реализовать). Есть вот такой код, помогите поправить.
#include<stdlib.h>
#include<iostream>
#include<fstream>
#include<string>
#include<iomanip>
using namespace std;
struct Cars
{
string brand;
string model;
int ID;
float cost;
string want;
};
Cars* Add(Cars* MyCar, int const count)
{
if (count == 0)
{
MyCar = new Cars[1];
}
else
{
Cars* temp = new Cars[count + 1];
for (int i = 0; i < count; i++)
{
temp[i] = MyCar[i];
}
delete[]MyCar;
MyCar = temp;
}
return MyCar;
}
void SetData(Cars* MyCar, int const count)
{
cout << "Enter brand\n"; getline(cin, MyCar[count].brand);
cout << "Enter model\n"; getline(cin, MyCar[count].model);
cout << "Enter price\n"; cin >> MyCar[count].cost;
cout << "Enter ID\n"; cin >> MyCar[count].ID;
}
void ShowData(Cars* MyCar, int const count)
{
int choice;
int threshold;
string want = "";
cout << "Enter what you want to see\n";
cout << "1 - Cars with prices greater than entered data\n";
cout << "2 - Cars with prices less than entered data\n";
cout << "3 - Cars of entered model\n";
cout << "4 - Detail information\n";
cin >> choice;
switch (choice)
{
case 1:
cout << "Enter threshold price\n";
cin >> threshold;
cout << setw(3) << "\t#\tBrand\tModel\tPrice\tID\n";
for (int i = 0; i < count; i++)
{
if (MyCar[i].cost >= threshold)
{
cout << setw(3) << i + 1 << "\t" << MyCar[i].brand << "\t" << MyCar[i].model << "\t" << MyCar[i].cost << "\t" << MyCar[i].ID << "\n";
}
else
{
cout << "No data\n";
return;
}
}
break;
case 2:
cout << "Enter threshold price\n";
cin >> threshold;
cout << setw(3) << "\t#\tBrand\tModel\tPrice\tID\n";
for (int i = 0; i < count; i++)
{
if (MyCar[i].cost <= threshold)
{
cout << setw(3) << i + 1 << "\t" << MyCar[i].brand << "\t" << MyCar[i].model << "\t" << MyCar[i].cost << "\t" << MyCar[i].ID << "\n";
}
else
{
cout << "No data\n";
return;
}
}
break;
case 3:
cout << "Enter the model you want see\n";
getline(cin, want);
cin.get();
cout << setw(3) << "#\tBrand\tModel\tPrice\tID\n";
for (int i = 0; i < count; i++)
{
if (MyCar[i].brand == MyCar[i].want)
{
cout << setw(3) << i + 1 << "\t" << MyCar[i].brand << "\t" << MyCar[i].model << "\t" << MyCar[i].cost << "\t" << MyCar[i].ID << "\n";
}
else
{
cout << "No data\n";
return;
}
}
break;
case 4:
cout << setw(3) << "#\tBrand\tModel\tPrice\tID\n";
for (int i = 0; i < count; i++)
{
cout << setw(3) << i + 1 << "\t" << MyCar[i].brand << "\t" << MyCar[i].model << "\t" << MyCar[i].cost << "\t" << MyCar[i].ID << "\n";
}
break;
default:
cout << "Wrong choice\n";
break;
}
}
int main()
{
Cars* MyCar = 0;
int count = 0;
bool YesOrNo = true;
do
{
MyCar = Add(MyCar, count);
SetData(MyCar, count);
count++;
cout << "Enter new data(1 - Yes, 0 - No)\n";
cin >> YesOrNo;
cin.get();
} while (YesOrNo);
ShowData(MyCar, count);
delete[]MyCar;
return 0;
}