Incorrect use of '='

3 ビュー (過去 30 日間)
Jarren Berdal
Jarren Berdal 2020 年 8 月 7 日
コメント済み: James Tursa 2020 年 8 月 7 日
disp('Ingrediants ID#');
disp('eggs: 10');
disp('avocado: 21');
disp('2 bread slices: 32');
disp('peanut butter: 43');
disp(' cup of spinich: 54');
disp('1/4 tbs of butter:65');
disp('slices of cheese: 76');
n = input('how many ingredients do you have');
%%FOOD INPUT
for k = 1:n
a(k) = input(sprintf('Type code of Ingrediant #%d: ',k ));
A(k) = input(sprintf('Type quantity of Ingrediant #%d: ',k ));
end
%%EGGAVOCADOSANDWICH
if (a(k) = 10)
elseif(a(k) = 21)
elseif (a(k) = 32
eggsandwich = (a(1)*A(1))+(a(2)*A(2))+(a(3)*A(3));
if eggsandwich >= 63
disp('egg avocado sandwich');
end
end
end
I am trying to have 3 conditions met by putting in a food ID number, once those three ID numbers are met, then it can proceed the formula displayed above. If it anser is above a certain number it would display that food.
'Incorrect use of '='. To assign a vlaue to a variable, use '=' . To compare values for equality, use '=='.

採用された回答

Fangjun Jiang
Fangjun Jiang 2020 年 8 月 7 日
use "==" for equal compare. It is in the error message.
  2 件のコメント
Jarren Berdal
Jarren Berdal 2020 年 8 月 7 日
now reads ' invalid expression
James Tursa
James Tursa 2020 年 8 月 7 日
Show your current code. The comparisons should be a(k)==10 etc.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeWaveform Generation についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by