Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024
Latihan C++ menggunakan setConsoleCursorPosition
1. Latihan 11
#include<iostream>
#include<conio.h>
#include<iomanip>
#include <windows.h >
using namespace std;
void gotoxy(int x, int y)
{
COORD coord;
coord.X=x;
coord.Y=y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coord);
}
int main()
{
char nama[30], barang[30];
int jumlah_barang, jumlah_beli = 0;
long harga_satuan, jumlah_harga, total_bayar = 0;
cout << "=== TOKO SERBA ADA === " << endl;
cout << "Nama Pembeli : " << endl;
cout << "Jumlah Barang yg Dibeli : " << endl;
gotoxy (27,1); cin >> nama;
gotoxy (27,2); cin >> jumlah_barang;
cout << endl;
cout << "=====================================================================" << endl;
cout << " | NO | NAMA BARANG | JUMLAH BELI | HARGA SATUAN | JUMLAH HARGA |" << endl;
cout << "=====================================================================" << endl;
for (int i = 1; i <= jumlah_barang; i++) {
gotoxy(1,i+6); cout << "|";
gotoxy(6,i+6); cout << "|";
gotoxy(24,i+6); cout << "|";
gotoxy(38,i+6); cout << "|";
gotoxy(53,i+6); cout << "|";
gotoxy(68,i+6); cout << "|";
gotoxy(3,i+6); cout << setw(2) << i;
}
cout << endl;
cout << "=====================================================================" << endl;
cout << " | TOTAL | |" << endl;
cout << "=====================================================================" << endl;
for (int j = 1; j <= jumlah_barang; j++) {
gotoxy(8,j+6); cin >> barang;
gotoxy(26,j+6); cin >> jumlah_beli;
2. gotoxy(40,j+6); cin >> harga_satuan;
jumlah_harga = jumlah_beli * harga_satuan;
gotoxy(55,j+6); cout << setw(12) << jumlah_harga;
total_bayar = total_bayar + jumlah_harga;
}
gotoxy(55,jumlah_barang+8); cout << setw(12) << total_bayar << endl;
gotoxy(1,jumlah_barang+11);cout << "TERIMA KASIH";
getch();
}
Permintaan:
1. Tambahkan informasi DISKON dan TOTAL BAYAR, dibawah informasi TOTAL
- DISKON didapat dari jika TOTAL lebih dari 10000, maka DISKON 10% dari TOTAL, jika tidak 0
- TOTAL BAYAR didapat dari TOTAL - DISKON
2. Buatkan Menu tambah data lagi, "INPUT DATA LAGI [Y/T]”