2013年7月10日 星期三

輸入數字組 Inputting set of numbers

我們將輸入一組數字並顯示在螢幕上。應用左鍵作「減」、右鍵作「加」及中鍵作「確定」並利用陣列的方式來讓我們可以使用迴圈四次來輸入四個數字,最後使用螢幕顯示指令來將輸入結果輸出。

We will input a set of numbers and display the set.  We can apply the left button to be "minus", right button to be "plus" and center button to be "confirm".  We can use the array to let us to apply loop for 4 times to input 4 numbers and output the result with display command finally.

Example:  

task main()
{
int a[4]={0,0,0,0},i=0;
while(i<4)
{
while(!ButtonPressed(BTNCENTER,true))
{
if(ButtonPressed(BTNRIGHT,true))a[i]++;
if(ButtonPressed(BTNLEFT,true))a[i]--;
NumOut(i*10,0,a[i]);
}
while(ButtonPressed(BTNCENTER,true))
i++;
}
while(i>0)
{
NumOut(i*10,10,a[i]);
i--;
}
Wait(5000);
}