Created
December 24, 2020 04:25
-
-
Save ajangrahmat/9360cee7a066343990c6edcf2167cec8 to your computer and use it in GitHub Desktop.
Menyimpan data Produk di Array, Menampilkan, Memilih Lokasi, Lalu menghitung Total Harga Diskonnya.
This file contains 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> | |
#include<string> | |
#include <cstdlib> | |
using namespace std; | |
long kode, harga, diskon; | |
string nama; | |
string produk[5][4] = { | |
{"1", "Table", "1000000", "10"}, | |
{"2", "Paper", "50000", "0"}, | |
{"3", "Envelopes", "15000", "10"}, | |
{"4", "Computer", "7000000", "15"}, | |
{"5", "Book Cases", "150000", "5"} | |
}; | |
int main() { | |
//Menampilkan Data pada Array Produk | |
cout << "DAFTAR PRODUK" << endl; | |
for (int k = 0; k <= 4; k++) { | |
for (int b = 0; b <= 3; b++) { | |
int TL = produk[k][b].length(); | |
cout << produk[k][b]; | |
if (TL < 7) | |
cout << "\t\t "; | |
else | |
cout << "\t "; | |
} | |
cout << endl; | |
} | |
cout << endl; | |
//Input kode | |
cout << "Masukan kode lokasi: "; | |
cin >> kode; | |
kode = kode - 1; | |
//Ambil data dari Array | |
nama = produk[kode][1]; | |
harga = atoi(produk[kode][2].c_str()); | |
diskon = atoi(produk[kode][3].c_str()); | |
//Proses Hitung Diskon | |
long potongan = (harga * diskon) / 100; | |
long total = harga - potongan; | |
//Tampilkan Output | |
cout << "Nama Item: " << nama << endl; | |
cout << "Harga: " << harga << endl; | |
cout << "Diskon: " << potongan << endl; | |
cout << "Harga setelah diskon: " << total << endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment