Ok, here is the way my code looks now
Code:
#include <iostream>
#include <fstream>
using namespace std;
struct car{
string make;
string model;
int year;
int price;
int mileage;
};
void search_make(car a[], int s, string val){
for (int i = 0; i < s; i++){
if (a[i].make == val){
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;
}
}
}
void search_model(car a[], int s, string val){
for (int i = 0; i < s; i++){
if (a[i].model == val){
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;
}
}
}
void search_year(car a[], int s, int val){
for (int i = 0; i < s; i++){
if (a[i].year == val){
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;
}
}
}
void search_price(car a[], int s, int val){
for (int i = 0; i < s; i++){
if (a[i].price == val){
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;
}
}
}
void search_mileage(car a[], int s, int val){
for (int i = 0; i < s; i++){
if (a[i].mileage == val){
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;
}
}
}
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;
delete[] search;
}
i.close();
return 0;
}
The problem I am having is with instruction number 7 (at the start of this thread). I'm not sure how to change my search functions so that if they put ANY for make and/or model, it will just disregard them. Also, how can I change my other search functions so they will search within a specific set of numbers? Thanks.