Ok, I combined all the functions into one, and it's working pretty well...
Code:
#include <iostream>
#include <fstream>
using namespace std;
struct car{
string make;
string model;
int year;
int price;
int mileage;
};
void search_all(car a[], int s, string make, string model, int yearfrom,
int yearto, int pricefrom, int priceto, int mileagefrom, int mileageto){
for (int i = 0; i < s; i++){
if (a[i].make == make){
cout << a[i].make << endl;
cout << a[i].model << endl;
cout << a[i].year << endl;
cout << a[i].price << endl;
cout << a[i].mileage << endl;
return;
}
else if (a[i].model == model){
cout << a[i].make << endl;
cout << a[i].model << endl;
cout << a[i].year << endl;
cout << a[i].price << endl;
cout << a[i].mileage << endl;
return;
}
else if ((a[i].year >= yearfrom) && (a[i].year <= yearto)){
cout << a[i].make << endl;
cout << a[i].model << endl;
cout << a[i].year << endl;
cout << a[i].price << endl;
cout << a[i].mileage << endl;
return;
}
else if ((a[i].price >= pricefrom) && (a[i].price <= priceto)){
cout << a[i].make << endl;
cout << a[i].model << endl;
cout << a[i].year << endl;
cout << a[i].price << endl;
cout << a[i].mileage << endl;
return;
}
else if ((a[i].mileage >= mileagefrom) && (a[i].mileage <= mileageto)){
cout << a[i].make << endl;
cout << a[i].model << endl;
cout << a[i].year << endl;
cout << a[i].price << endl;
cout << a[i].mileage << endl;
return;
}
}
}
int main(){
ifstream i;
i.open("data1");
int size = 50;
for (int x = 0; x < size; x++){
car *search = new car[size];
if (x == size){
car *temp = search;
size += size;
search = temp;
}
while (i >> search[x].make){
i >> search[x].model >> search[x].year >>
search[x].price >> search[x].mileage;
}
string model, make;
int yearfrom, yearto, pricefrom, priceto, mileagefrom, mileageto;
cout << " Please enter search criteria:" << endl;
cout << " Make: ";
cin >> make;
cout << " Model: ";
cin >> model;
cout << " Year from: ";
cin >> yearfrom;
cout << " Year to: ";
cin >> yearto;
cout << " Price from: ";
cin >> pricefrom;
cout << " Price to: ";
cin >> priceto;
cout << " Mileage from: ";
cin >> mileagefrom;
cout << " Mileage to: ";
cin >> mileageto;
search_all (search, size, make, model, yearfrom, yearto,
pricefrom, priceto, mileagefrom, mileageto);
delete[] search;
break;
}
i.close();
return 0;
}
The only problem is, it's only outputting one set of data, even if the criteria I put in matches different records in the data file. I know it has something to do with my if/else statements, but I can't figure out what. How can I change them so that it will output a set of data for each match that it finds? Oh yeah, and there's that little "ANY" problem. I still can't figure that one out.