1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
|
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
void StartScreen(int five, int ten, int twenty, int fifty, double total){
cout << "\n \n \n ..: JAQK POT :.. " << endl;
cout << " ****************************" << endl;
cout << " Jack Ace Queen King" << endl;
cout << " 5c 10c 20c 50c " << endl;
cout << " " << five << " " << ten << " "<< twenty << " " << fifty << endl;
cout << "\n Total = RM" << total << endl;
}
void clScreen(){
for(int i = 0; i < 100; ++i){
cout << "\n";
}
}
int main()
{
char start;
cout << "+----------------------+" << endl;
cout << "| ------------------ |" << endl;
cout << "| |" << endl;
cout << "| ------------ |" << endl;
cout << "+----------------------+" << endl;
cout << "\n Press any key to continue . . .";
cin >> start;
clScreen();
string x, exit = "p";
srand (time(NULL));
int max = 10;
int five = rand() % max;
max -= five;
int ten = rand() % max;
max -= ten;
int twenty = rand() % max;
max -= twenty;
int fifty = max;
int j, a, k, q;
double total = five*0.05 + ten*0.1 + twenty*0.2 + fifty*0.5, amount;
double c05 = 0, c10 = 0, c20 = 0, c50 = 0;
while (exit != "N" && exit != "n"){
clScreen();
StartScreen(five, ten, twenty, fifty, total);
cout << "\n Press D or d if you want to deposit." << endl;
cout << " Press W or w if you want to withdraw." << endl;
cout << " Press R or r if you want to reset." << endl;
cout << "==>";
cin >> x;
if(x == "D" || x == "d"){
cout << "How many 5c coins? ==> ";
cin >> j;
five += j;
cout << "How many 10c coins? ==> ";
cin >> a;
ten += a;
cout << "How many 20c coins? ==> ";
cin >> q;
twenty += q;
cout << "How many 50c coins? ==> ";
cin >> k;
fifty += k;
} else if (x == "W" || x == "w"){
cout << "Please enter the amount (in RM) => ";
cin >> amount;
int tmp = amount*100;
if(tmp%5 != 0 || amount > total){
cout << "INVALID";
} else {
while(amount > 0){
if(fifty > 0 && amount >= 0.5){
fifty -= 1;
c50 += 1;
amount -= 0.5;
} else if (twenty > 0 && amount >= 0.2){
twenty -= 1;
c20 += 1;
amount -= 0.2;
} else if (ten > 0 && amount >= 0.1){
ten -= 1;
c10 += 1;
amount -= 0.1;
} else if (five > 0 && amount >= 0.05){
five -= 1;
c05 += 1;
amount -= 0.05;
}
}
cout << "Yes, Please collect your coins: ";
if (c50 > 0){
cout << "\n 50c x " << c50 << endl;
cout << "20c x " << c20 << endl;
cout << "10c x " << c10 << endl;
cout << "5c x " << c05 << endl;
}
}
} else if (x == "R" || x == "r"){
cout << "How many 5c coins? ==> ";
cin >> five;
cout << "How many 10c coins? ==> ";
cin >> ten;
cout << "How many 20c coins? ==> ";
cin >> twenty;
cout << "How many 50c coins? ==> ";
cin >> fifty;
} else {
cout << "Invalid input";
}
StartScreen(five, ten, twenty, fifty, total);
total = five*0.05 + ten*0.1 + twenty*0.2 + fifty*0.5;
cout << "\n Total = RM" << total << endl;
cout << "\n Please press any key to continue," << endl;
cout << " press N or n to exit the program => ";
cin >> exit;
}
return 0;
}
|