## My pie chart wont show up

This is my main file.

clear; clc;

% Main script

disp(‘Welcome to Recipe Cost Calculator’);

choice = menu(‘Select an option:’, ‘Calculate Recipe Cost’, ‘Exit’); %%this creates a button where it says calculate the recipe cost or to exit out of the program

while choice ~= 2 %%this line just means that while the user doesn’t chose the 2nd option, which is exit(laue of 2), then the program will continue to run

switch choice %%I decided to insert a switch stament for 2 different senarios. either case1 or case 2

case 1

disp(‘Enter ingredients for the recipe:’); %% this just displys this statment. where is where the user can input that the ingridient is

[ingredients, quantities, prices] = getRecipeInput(); %this getRecipeInput();is the 3 out pts and ive assigned each what they are

totalCost = calculateRecipeCost(ingredients, quantities, prices); %% this clalculates the total cost based off of the ingridients, how many ingridients and the price of the ingridients

disp([‘Total cost of the recipe: $’, num2str(totalCost)]); %%this displays the total cost. Instead of just giving the numerical value the user has to know that this is the total cost of all the ingidients listed.

plotCostBreakdown(ingredients, quantities, prices); %% this genetrates a pie chart of the ingidients quantities and cost

case 2 %% if the user presses option 2 then the program exits

disp(‘Exiting…’); %this displays that the program with exit

return;

end

choice = menu(‘Select an option:’, ‘Calculate Recipe Cost’, ‘Exit’); %%then it loops back and the user can chose either iption 1 or 2 again

end

The I have 3 seperate function files.

function file 1 –

function totalCost = calculateRecipeCost(ingredients, quantities, prices) % this calculates the total cost

totalCost = sum(quantities .* prices); %%This multiplies each ingridinent cost and then sums up the prices together

%This function calculates the total cost of a recipe based on the

% provided ingredients, quantities, and prices.

end

function file 2 –

%UNTITLED4 Summary of this function goes here

% Detailed explanation goes here

function [ingredients, quantities, prices] = getRecipeInput()

ingredients = {}; %these have empty arrays so that the user inputs the price it can show

quantities = [];%these have empty arrays so that the user inputs the price it can show

prices = [];%these have empty arrays so that the user inputs the price it can show

while true %white this statment is true

ingredient = input(‘Enter ingredient name (or type "done" to finish): ‘, ‘s’); %% this is so that the user inputs the name of the ingidient

if strcmp(ingredient, ‘done’) %% this is so that when the user is done inputing ingredients, quantities, and price, the user can input done and it will calculate the total cost

break; % then it breaks while the loop

end

quantity = input(‘Enter quantity: ‘); % the user inputs quantity of the ingidient

price = input(‘Enter price per unit: ‘); % the user inputs the price

ingredients = [ingredients, ingredient]; %% these put the ingridients in an array with the quanitities and price of each ingridient

quantities = [quantities, quantity];

prices = [prices, price];

end

end

function file 3 –

%UNTITLED5 Summary of this function goes here

% Pie chart of cost breakdown

% Define function to plot cost breakdown

function costBreakdown(ingredients, quantities, prices)

% Generate pie chart

figure;

pie(prices .* quantities, ingredients);

title(‘Cost Breakdown’);

% Add legend and labels

legend(ingredients, ‘Location’, ‘BestOutside’);

ylabel(‘Cost’);

end

Please help me!!!This is my main file.

clear; clc;

% Main script

disp(‘Welcome to Recipe Cost Calculator’);

choice = menu(‘Select an option:’, ‘Calculate Recipe Cost’, ‘Exit’); %%this creates a button where it says calculate the recipe cost or to exit out of the program

while choice ~= 2 %%this line just means that while the user doesn’t chose the 2nd option, which is exit(laue of 2), then the program will continue to run

switch choice %%I decided to insert a switch stament for 2 different senarios. either case1 or case 2

case 1

disp(‘Enter ingredients for the recipe:’); %% this just displys this statment. where is where the user can input that the ingridient is

[ingredients, quantities, prices] = getRecipeInput(); %this getRecipeInput();is the 3 out pts and ive assigned each what they are

totalCost = calculateRecipeCost(ingredients, quantities, prices); %% this clalculates the total cost based off of the ingridients, how many ingridients and the price of the ingridients

disp([‘Total cost of the recipe: $’, num2str(totalCost)]); %%this displays the total cost. Instead of just giving the numerical value the user has to know that this is the total cost of all the ingidients listed.

plotCostBreakdown(ingredients, quantities, prices); %% this genetrates a pie chart of the ingidients quantities and cost

case 2 %% if the user presses option 2 then the program exits

disp(‘Exiting…’); %this displays that the program with exit

return;

end

choice = menu(‘Select an option:’, ‘Calculate Recipe Cost’, ‘Exit’); %%then it loops back and the user can chose either iption 1 or 2 again

end

The I have 3 seperate function files.

function file 1 –

function totalCost = calculateRecipeCost(ingredients, quantities, prices) % this calculates the total cost

totalCost = sum(quantities .* prices); %%This multiplies each ingridinent cost and then sums up the prices together

%This function calculates the total cost of a recipe based on the

% provided ingredients, quantities, and prices.

end

function file 2 –

%UNTITLED4 Summary of this function goes here

% Detailed explanation goes here

function [ingredients, quantities, prices] = getRecipeInput()

ingredients = {}; %these have empty arrays so that the user inputs the price it can show

quantities = [];%these have empty arrays so that the user inputs the price it can show

prices = [];%these have empty arrays so that the user inputs the price it can show

while true %white this statment is true

ingredient = input(‘Enter ingredient name (or type "done" to finish): ‘, ‘s’); %% this is so that the user inputs the name of the ingidient

if strcmp(ingredient, ‘done’) %% this is so that when the user is done inputing ingredients, quantities, and price, the user can input done and it will calculate the total cost

break; % then it breaks while the loop

end

quantity = input(‘Enter quantity: ‘); % the user inputs quantity of the ingidient

price = input(‘Enter price per unit: ‘); % the user inputs the price

ingredients = [ingredients, ingredient]; %% these put the ingridients in an array with the quanitities and price of each ingridient

quantities = [quantities, quantity];

prices = [prices, price];

end

end

function file 3 –

%UNTITLED5 Summary of this function goes here

% Pie chart of cost breakdown

% Define function to plot cost breakdown

function costBreakdown(ingredients, quantities, prices)

% Generate pie chart

figure;

pie(prices .* quantities, ingredients);

title(‘Cost Breakdown’);

% Add legend and labels

legend(ingredients, ‘Location’, ‘BestOutside’);

ylabel(‘Cost’);

end

Please help me!!! This is my main file.

clear; clc;

% Main script

disp(‘Welcome to Recipe Cost Calculator’);

choice = menu(‘Select an option:’, ‘Calculate Recipe Cost’, ‘Exit’); %%this creates a button where it says calculate the recipe cost or to exit out of the program

while choice ~= 2 %%this line just means that while the user doesn’t chose the 2nd option, which is exit(laue of 2), then the program will continue to run

switch choice %%I decided to insert a switch stament for 2 different senarios. either case1 or case 2

case 1

disp(‘Enter ingredients for the recipe:’); %% this just displys this statment. where is where the user can input that the ingridient is

[ingredients, quantities, prices] = getRecipeInput(); %this getRecipeInput();is the 3 out pts and ive assigned each what they are

totalCost = calculateRecipeCost(ingredients, quantities, prices); %% this clalculates the total cost based off of the ingridients, how many ingridients and the price of the ingridients

disp([‘Total cost of the recipe: $’, num2str(totalCost)]); %%this displays the total cost. Instead of just giving the numerical value the user has to know that this is the total cost of all the ingidients listed.

plotCostBreakdown(ingredients, quantities, prices); %% this genetrates a pie chart of the ingidients quantities and cost

case 2 %% if the user presses option 2 then the program exits

disp(‘Exiting…’); %this displays that the program with exit

return;

end

choice = menu(‘Select an option:’, ‘Calculate Recipe Cost’, ‘Exit’); %%then it loops back and the user can chose either iption 1 or 2 again

end

The I have 3 seperate function files.

function file 1 –

function totalCost = calculateRecipeCost(ingredients, quantities, prices) % this calculates the total cost

totalCost = sum(quantities .* prices); %%This multiplies each ingridinent cost and then sums up the prices together

%This function calculates the total cost of a recipe based on the

% provided ingredients, quantities, and prices.

end

function file 2 –

%UNTITLED4 Summary of this function goes here

% Detailed explanation goes here

function [ingredients, quantities, prices] = getRecipeInput()

ingredients = {}; %these have empty arrays so that the user inputs the price it can show

quantities = [];%these have empty arrays so that the user inputs the price it can show

prices = [];%these have empty arrays so that the user inputs the price it can show

while true %white this statment is true

ingredient = input(‘Enter ingredient name (or type "done" to finish): ‘, ‘s’); %% this is so that the user inputs the name of the ingidient

if strcmp(ingredient, ‘done’) %% this is so that when the user is done inputing ingredients, quantities, and price, the user can input done and it will calculate the total cost

break; % then it breaks while the loop

end

quantity = input(‘Enter quantity: ‘); % the user inputs quantity of the ingidient

price = input(‘Enter price per unit: ‘); % the user inputs the price

ingredients = [ingredients, ingredient]; %% these put the ingridients in an array with the quanitities and price of each ingridient

quantities = [quantities, quantity];

prices = [prices, price];

end

end

function file 3 –

%UNTITLED5 Summary of this function goes here

% Pie chart of cost breakdown

% Define function to plot cost breakdown

function costBreakdown(ingredients, quantities, prices)

% Generate pie chart

figure;

pie(prices .* quantities, ingredients);

title(‘Cost Breakdown’);

% Add legend and labels

legend(ingredients, ‘Location’, ‘BestOutside’);

ylabel(‘Cost’);

end

Please help me!!! help, pie chart, matlab code, matlab, i need help, array, chart, graph MATLAB Answers — New Questions