-
Notifications
You must be signed in to change notification settings - Fork 0
/
uas.cpp
71 lines (60 loc) · 2.25 KB
/
uas.cpp
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
#include <iostream>
using namespace std;
struct transaksi {
string nama_barang;
int harga_satuan;
int jumlah_beli;
int sub_total;
double diskon;
double total_harga;
};
transaksi t[100];
int main() {
system("cls");
cout << "=======================================" << endl;
cout << " TOKO BUKU DARMAJAYA THE BEST" << endl;
cout << " Jl. Pramuka No. 35 A Bandar Lampung" << endl;
cout << "=======================================" << endl;
int jumlah_transaksi;
cout << "Jumlah Transaksi: ";
cin >> jumlah_transaksi;
int total_sub_total = 0;
double total_diskon = 0;
double total_harga = 0;
for (int i = 0; i < jumlah_transaksi; i++) {
cout << "\n\nTransaksi ke-" << (i+1) << endl;
cout << "---------------------------------------" << endl;
cout << "Nama Barang: ";
cin.ignore();
getline(cin, t[i].nama_barang);
cout << "Harga Satuan: ";
cin >> t[i].harga_satuan;
cout << "Jumlah Beli: ";
cin >> t[i].jumlah_beli;
t[i].sub_total = t[i].harga_satuan * t[i].jumlah_beli;
if (t[i].jumlah_beli >= 5) {
t[i].diskon = t[i].sub_total * 0.03;
} else {
t[i].diskon = 0;
}
t[i].total_harga = t[i].sub_total - t[i].diskon;
// menambahkan hasil perhitungan ke variabel total
total_sub_total += t[i].sub_total;
total_diskon += t[i].diskon;
total_harga += t[i].total_harga;
cout << "---------------------------------------" << endl;
cout << "Sub Total: " << t[i].sub_total << endl;
cout << "Diskon: " << t[i].diskon << endl;
cout << "---------------------------------------" << endl;
cout << "Total Harga Barang Ini: " << t[i].total_harga << endl;
cout << "=======================================" << endl;
}
cout << "\n\n---------------------------------------" << endl;
cout << "Total Sub Total: " << total_sub_total << endl;
cout << "Total Diskon: " << total_diskon << endl;
cout << "---------------------------------------" << endl;
cout << "Total Harga Semua Barang: " << total_harga << endl;
cout << "=======================================" << endl;
cout << "Programmer: Rizky Juniardi" << endl;
return 0;
}