% Create structure to contain car information
% blah
% blah
% blah

% create the car structure
car = struct('make',{},'model',{},'year',{},'mileage',{},'class',{},'color',{});

% add 3 vehicles to our system
car(1).make = 'Chevrolet';
car(1).model = 'Corvette';
car(1).year = '2016';
car(1).mileage = '22,126';
car(1).class = 'Sports Car';
car(1).color = 'Red';

car(2).make = 'Ford';
car(2).model = 'F150';
car(2).year = '1991';
car(2).mileage = '134,234';
car(2).class = 'Truck';
car(2).color = 'White';

car(3).make = 'Cadillac';
car(3).model = 'Escalade';
car(3).year = '2015';
car(3).mileage = '32,023';
car(3).class = 'SUV';
car(3).color = 'Silver';

% establish counter element for adding cars in loop
moreCars = 'y';
count = 3;

% greeting message and display current vehicles
fprintf('Welcome to our vehicle storage system!\n\n');

fprintf('Here is a listing of vehicles already in our system \n\n');

fprintf('%12s %12s %12s %12s %12s %12s\n','make','model','year','mileage','class','color');
fprintf('-------------------------------------------------------------------------------\n');

for i=1:count
    
    fprintf('%12s %12s %12s %12s %12s %12s\n',car(i).make,car(i).model,car(i).year,car(i).mileage,car(i).class,car(i).color);

end

fprintf('\n\n');

while strcmp(moreCars,'y')
    
    % begin counter here to end up with the total number of vehicles
    count = count + 1;
    
    % save new values to our structure
    car(count).make = input('make: ','s');
    car(count).model = input('model: ','s');
    car(count).year = input('year: ','s');
    car(count).mileage = input('mileage: ','s');
    car(count).class = input('class: ','s');
    car(count).color = input('color: ','s');
    
    % set upper limit to be one less than current vehicel (so we don't check against itself)
    newCount = count - 1;
    
    % check existing entries to current entry to see if we have matches
    for i=1:newCount
       
        if strcmp(car(i).make,car(count).make) && strcmp(car(i).model,car(count).model) && strcmp(car(i).year,car(count).year)
        
            disp('We have a similar vehicle already in our system!');
            fprintf('Our vehicle: %s %s %s\n',car(i).year,car(i).make,car(i).model);
            
        end
        
        % display the entered data back to user
        fprintf('Your vehicle: %s %s %s\n\n',car(count).year,car(count).make,car(count).model);
        
    end
    
    % 
    moreCars = input('Would you like to enter another vehicle? (y,n) ','s');
    
end

% ask whether user wants to see all vehicles
showAll = input('Would you like to see the full inventory list? (y,n)','s');

if strcmp(showAll,'y')
   
    fprintf('Here is a listing of every vehicle now in our system \n\n');

    % display our finalized table
    fprintf('%12s %12s %12s %12s %12s %12s\n','make','model','year','mileage','class','color');
    
    fprintf('-------------------------------------------------------------------------------\n');

    for i=1:count

        fprintf('%12s %12s %12s %12s %12s %12s\n',car(i).make,car(i).model,car(i).year,car(i).mileage,car(i).class,car(i).color);

    end
    
end

% exit
disp('Thank you for using our vehicle management system!');