071501 - Currency Conversion
題目敘述 Problems Description:
請寫一個程式可以做幣值換算,可供兌換的幣值有: 1. 台幣(NTD) 2. 英鎊(GBP) 3. 韓元(KRW) 4. 美金(USD) 5. 日元(JPY)
輸入end
則程式結束。若輸入GBP
,KRW
,NTD
,USD
,JPY
,end
以外的指令則輸出 ”ERROR!! Input again!!” 並重複輸入直到有正確的指令才繼續執行。
Please write a program to do currency conversion. The available currency values are: 1. New Taiwan dollar(NTD) 2. British pound(GBP) 3. Korean won(KRW) 4. US dollar(USD) 5. Japanese yen(JPY)
If you input end
, then terminate your program. If you input commands except GBP
,KRW
,NTD
,USD
,JPY
,end
, then output "ERROR!! Input again!!"
Hint:
1 GBP = 37.7412 NTD
1 GBP = 1526.73 KRW
1 GBP = 1.2588 USD
1 GBP = 134.99 JPY
輸入說明 Input Description:
輸入順序:
1. X(需要被轉換的幣種:GBP
,KRW
,NTD
,USD
,JPY
, 或終止指令: end
)
2. N(要兌換幣種X的金額,且為實數)
3. Y(幣種X要選擇兌換的幣種,若為end
則算輸入錯誤)
Input sequence:
1. X(currency type need to be converted:GBP
,KRW
,NTD
,USD
,JPY
, or terminal command: end
)
2. N(the amount of currency x need to be converted, N is a real number)
3. Y(currency type need to convert, but if it's a terminal command: end
, print "ERROR!! Input again!!")
輸出說明 Output Description:
全部的幣值為浮點數,幣值 X 的 N 元兌換成幣值 Y(取到小數點後第三位,記得四捨五入)。若輸入的 X 或 Y 有錯誤則輸出 "ERROR!! Input again!!"。而若 N<0 則輸出"N cannot smaller than 0!! Input again!!"。
All of numbers is float, and convert the amount N of currency X to currency Y (take the third decimal place, remember to round up). If the input X or Y is wrong, output "ERROR !! Input again !!", if N <0 then output “N cannot smaller than 0!! Input again!!"
輸入範例 Input Example:
NTD 100 KRW GBBs KRW -20 50 end JPY end
輸出範例 Output Example:
100.0 NTD = 4045.261 KRW ERROR!! Input again!! N cannot smaller than 0!! Input again!! ERROR!! Input again!! 50.0 KRW = 4.421 JPY
提示 Hint:
請搭配 字典 來解決該問題。
Please use Dictionary to help you solve this problem.
最后更新于
这有帮助吗?