I was given the task of matlab. but my function cannot run and gives an error of "Undefined function or variable 'b'." can someone help me ?
Cindy uses the services of a brokerage firm to buy and sell stocks. The firm charges 1.5% service
charges on the total amount for each transaction, buy or sell. When Cindy sells stocks, she would
like to know if she gained or lost on a particular investment. Write a program that allows Cindy
to input the number of shares sold, the purchase price of each share, and the selling price of
each share. The program outputs the amount invested, the total service charges, amount gained
or lost, and the amount received after selling the stock.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
share = input('What is your share price? ');
option = input('Do you wish to buy or sell? <b/s> ');
if (option == 'b' || option == 'B')
buy = input('How many units do you wish to purchase? ');
totbuy = share*buy;
netbuy = totbuy - 0.015*totbuy;
fprintf('Your total share purchased is %f, totbuy');
fprintf('Your net share purchased is %f, netbuy');
elseif(option == 's' || option == 'S')
sell = input('How many units do you wish to sell? ');
totsell = share*sell;
netsell = totsell - 0.015*totsell;
fprintf('Your total share sold is %f, totsell');
fprintf('Your net share sold is %f, netsell');
else
disp('Transaction invalid');
end
|