¿Why doesn't work this algorithm about commissions and sales?

Hello everyone, help is really appreciated here, I need help to know why the following algorithm doesn't work, please. ¿What I'm doing wrong? ¿Does the code lack something?
Sorry, English is not my native language.
TEXT:
A seller needs to know his total commissions for selling multiple items. The seller get 10% commission based on the total price of the sales. Develop an algorithm that allows the seller to know how much money he earned from commissions if he did N sales, type N as a condition (WHILE).
You have to use WHILE. Don't use IF, ELSE, etc.
This is the code and does't work, please help.
CODE
PC = 0.1; % 10 percent of the commission
i = 1;
sum = 0;
C = 0; % commissions
N = input('Enter all the sales: ');
while i < N || i == N;
i = i+1;
sum = sum+i;
C = N*PC; % commissions
end
disp('You earned:');
disp(C);
Thanks.

1 件のコメント

Jan
Jan 2012 年 11 月 21 日
Please explain what "does not work" explicitly means: Do you get an error message (if so, copy it completely) or do the results differ from your expectations (if so explain both)?

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

 採用された回答

Jan
Jan 2012 年 11 月 21 日

0 投票

The "while" command iterate its body until the condition is met. For this reason the condition must change inside the loop. But in your code neither "i" nor "N" is touched inside the loop body, such that you get a loop which either runs infinitely or not even one time (if N <= 1).

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeParallel Computing についてさらに検索

製品

質問済み:

2012 年 11 月 21 日

Community Treasure Hunt

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

Start Hunting!

Translated by