Created
December 1, 2013 18:54
-
-
Save peerasak-u/7739276 to your computer and use it in GitHub Desktop.
188110-midterm-2011-2 ข้อ 5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| using namespace::std; | |
| int main() | |
| { | |
| int inputMoney = 0; | |
| int moneyCard = 0; | |
| int moneyChanged = 0; | |
| cout << "Please insert money: "; | |
| //Input Money | |
| cin >> inputMoney; | |
| cout << "Received: " << inputMoney <<" Baths" << endl; | |
| //Compare inputMoney and Money Card (100, 200, 300) | |
| //InputMoney must equal or greater than 100 | |
| if (inputMoney >= 100) { | |
| if (inputMoney >= 300) { | |
| moneyCard = 300; | |
| }else if (inputMoney >= 200) { | |
| moneyCard = 200; | |
| }else { | |
| moneyCard = 100; | |
| } | |
| cout << "Money card: " << moneyCard <<" Baths" << endl; | |
| //Calculate Changed Money | |
| moneyChanged = inputMoney - moneyCard; | |
| cout << "Changed: " << moneyChanged <<" Baths" << endl; | |
| }else { | |
| //If input money is too low, Show this error message | |
| cout << "Sorry, you don't have enough money" << endl; | |
| cout << "Changed: " << inputMoney <<" Baths" << endl; | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment