Skip to content

Instantly share code, notes, and snippets.

@peerasak-u
Created December 1, 2013 18:54
Show Gist options
  • Select an option

  • Save peerasak-u/7739276 to your computer and use it in GitHub Desktop.

Select an option

Save peerasak-u/7739276 to your computer and use it in GitHub Desktop.
188110-midterm-2011-2 ข้อ 5
#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