....

2014年5月23日 星期五

[長知識] C語言 - 新手篇章 - 利用方法將ID搜尋的獎金列出

#include <stdio.h>
#include <stdlib.h>


//怕main在使用getLottery()的時候不認識,所以寫在main上面
int getLottery(int id);

int main(int argc, char *argv[]) {

int id;
printf("請輸入ID!");
scanf("%i", &id);

int award = getLottery(id);
if(award <= 0){
printf("銘謝惠顧!");
}else{
printf("YOUR AWARD:%i" ,award);
}



}

int getLottery(int id){

switch(id%5){
case 0:
return 10000;
case 1:
return 20000;
case 2:
return 30000;
case 3:
return 40000;
}
//default 其他回傳0
return 0;
}


沒有留言:

張貼留言