....

2014年5月17日 星期六

[長知識] C語言 - 新手篇章 - switch case && if 銀行開戶問題

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

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

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

int money;
char bankID;


printf("請問你要在哪間銀行開戶?\nA:玉山\nB:花旗\nC:中信");
scanf("%c", &bankID);
printf("要存多少錢?\n");
scanf("%i", &money);
bankID = toupper(bankID);

switch(bankID){
case 'A':
if(money>45000) printf("歡迎開戶");
else printf("開戶金額不足");
break;

case 'B':
if(money>55000) printf("歡迎開戶");
else printf("開戶金額不足");
break;

case 'C':
if(money>65000) printf("歡迎開戶");
else printf("開戶金額不足");
break;

default:
break;
}


return 0;
}

沒有留言:

張貼留言