Code
Code
Code
#include <string>
#include <iomanip>
#include <map>
using namespace std;
int potongan = 0;
auto it = promoDiscounts.find(kodePromo);
if (it != promoDiscounts.end()) {
potongan = total * it->second / 100;
}
return potongan;
}
int main() {
int loginAttempts = 3;
string username, password;
int totalAfterPajak = 0; // Declare totalAfterPajak outside the case 1 block
if (loginAttempts == 0) {
cout << "Anda telah mencapai batas maksimal percobaan login. Program berhenti.\n";
return 0;
}
int menu;
string namaPenyewa, kodeMobil, namaMobil, tanggalMenyewa, kodePromo;
int days, price, total = 0, subtotal, potongan;
float pajak;
bool continueProgram = true;
while (continueProgram) {
cout << "===========================\n";
cout << "Menu Utama :\n";
cout << "1. Input Transaksi\n";
cout << "2. Cetak Transaksi Terakhir\n";
cout << "3. Keluar\n";
cout << "Input Menu [1-3]: ";
cin >> menu;
// Calculate Data
subtotal = calculateTotal(days, price);
pajak = calculatePajak(subtotal);
totalAfterPajak = calculateTotalAfterPajak(subtotal, pajak);
// Calculate Potongan
potongan = calculatePotongan(totalAfterPajak, kodePromo);
// Update Total
total = totalAfterPajak - potongan;
// Output Data
printTransaction(namaPenyewa, tanggalMenyewa, days, kodeMobil, namaMobil, price,
subtotal, pajak, totalAfterPajak, kodePromo, potongan, total);
break;
}
case 2:
// Cetak Transaksi Terakhir
if (total == 0) {
cout << "===========================\n";
cout << "Belum Ada Data Transaksi Pembayaran.\n";
} else {
cout << "===========================\n";
cout << "Data Transaksi Terakhir:\n";
printTransaction(namaPenyewa, tanggalMenyewa, days, kodeMobil, namaMobil,
price, subtotal, pajak, totalAfterPajak, kodePromo, potongan, total);
}
break;
case 3:
// Keluar
cout << "===========================\n";
cout << "Program Berhenti.\n";
continueProgram = false;
break;
default:
cout << "Menu tidak valid.\n";
break;
}
return 0;
}