write code for having a grocery shopping list where i can input manually the entries and the categories and it's displayed during this week in matlab

Here's an example code for creating a grocery shopping list in MATLAB:

main.m
% Initialize variables
items = [];
categories = [];

% Get inputs from user
while true
    item = input('Enter item: ', 's');
    category = input('Enter category: ', 's');
    
    % Add inputs to arrays
    items = [items; item];
    categories = [categories; category];
    
    % Ask user if they want to continue adding items
    cont = input('Add another item? (y/n): ', 's');
    if strcmpi(cont, 'n')
        break;
    end
end

% Print grocery list
fprintf('\nGrocery List\n');
fprintf('------------\n');
for i = 1:length(items)
    fprintf('%s (%s)\n', items{i}, categories{i});
end
593 chars
27 lines

This code prompts the user to enter items and categories, and stores them in arrays. The user can input as many items as they want by typing "y" when asked if they want to continue adding items. Once the user is done, the code prints out the grocery list with each item and its corresponding category.

You can modify this code to fit your specific needs such as adding date/time and more.

related categories

gistlibby LogSnag