Advertisement
0xl0g1c

shipping-rates

Nov 4th, 2022 (edited)
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.72 KB | Source Code | 0 0
  1. /*
  2.     Author      : Wahyu Priambodo (2207421048)
  3.     Class       : TMJ 1B
  4.     Created on  : Friday, Nov 4, 2022
  5. */
  6.  
  7. // ref link: https://titipbeliin.com/blog/cek-ongkir-dakota-cargo/
  8. #include <iostream>
  9. #include <conio.h>
  10. #include <cstdlib>
  11. #include <iomanip>
  12. #define nl "\n"
  13.  
  14. #ifdef _WIN32
  15. #define clr "cls"
  16. #else //In any other OS
  17. #define clr "clear"
  18. #endif
  19.  
  20. using namespace std;
  21.  
  22. int main(int argc, char *argv[]) {
  23.     /* Biaya Ongkir di 10 Kota Besar:
  24.         1.) Jakarta     (29.000) -> 1.450
  25.         2.) Semarang    (68.000) -> 3.400
  26.         3.) Bekasi      (53.000) -> 2.650
  27.         4.) Bandung     (24.000) -> 2.900
  28.         5.) Malang      (57.000) -> 2.850
  29.         6.) Yogyakarta  (41.000) -> 2.050
  30.         7.) Subang      (52.000) -> 2.600
  31.         8.) Surabaya    (54.000) -> 2.700
  32.         9.) Denpasar    (67.000) -> 3.350
  33.         10.) Salatiga   (44.000) -> 2.200
  34.     */
  35.     int to, // destination
  36.     p, l, t; // weight dimension
  37.    
  38.     long long total = 0;
  39.     float weight = 0;
  40.    
  41.     while(1) {
  42.         char next;
  43.        
  44.         cout << "===== [CEK ONGKIR DAKOTA CARGO] =====" << nl;
  45.         cout << "List Kota yang Tersedia:" << nl;
  46.         cout << "1.) Jakarta" << nl;
  47.         cout << "2.) Semarang" << nl;
  48.         cout << "3.) Bekasi" << nl;
  49.         cout << "4.) Bandung" << nl;
  50.         cout << "5.) Malang" << nl;
  51.         cout << "6.) Yogyakarta" << nl;
  52.         cout << "7.) Subang" << nl;
  53.         cout << "8.) Surabaya" << nl;
  54.         cout << "9.) Denpasar" << nl;
  55.         cout << "10.) Salatiga" << nl;
  56.        
  57.         cout << "Pilih kota tujuan (1-10): "; cin >> to;
  58.         if(to < 1 && to > 10) {
  59.             cout << nl;
  60.             cerr << "!! Kota Tujuan sedang Tidak Tersedia !!" << nl;
  61.             goto REPEAT;
  62.         }
  63.         else {
  64.             cout << "Input panjang box : "; cin >> p;
  65.             cout << "Input lebar box : "; cin >> l;
  66.             cout << "Input tinggi box : "; cin >> t;
  67.             weight = (p * l * t) / 4000;
  68.         }
  69.        
  70.         switch(to) {
  71.             case 1: // Jakarta
  72.                 if(weight <= 20) {
  73.                     total += 29000;
  74.                 }
  75.                 else {
  76.                     total = 29000 + (1450 * (weight-20));
  77.                 }
  78.                 break;
  79.                
  80.             case 2: // Semarang
  81.                 if(weight <= 20) {
  82.                     total += 68000;
  83.                 }
  84.                 else {
  85.                     total = 68000 + (3400 * (weight-20));
  86.                 }
  87.                 break;
  88.            
  89.             case 3: // Bekasi
  90.                 if(weight <= 20) {
  91.                     total += 53000;
  92.                 }
  93.                 else {
  94.                     total = 53000 + (2650 * (weight-20));
  95.                 }
  96.                 break;
  97.            
  98.             case 4: // Bandung
  99.                 if(weight <= 20) {
  100.                     total += 24000;
  101.                 }
  102.                 else {
  103.                     total = 24000 + (2900 * (weight-20));
  104.                 }
  105.                 break;
  106.            
  107.             case 5: // Malang
  108.                 if(weight <= 20) {
  109.                     total += 57000;
  110.                 }
  111.                 else {
  112.                     total = 57000 + (2850 * (weight-20));
  113.                 }
  114.                 break;
  115.                
  116.             case 6: // Yogyakarta
  117.                 if(weight <= 20) {
  118.                     total += 41000;
  119.                 }
  120.                 else {
  121.                     total = 41000 + (2050 * (weight-20));
  122.                 }
  123.                 break;
  124.                
  125.             case 7: // Subang
  126.                 if(weight <= 20) {
  127.                     total += 52000;
  128.                 }
  129.                 else {
  130.                     total = 52000 + (2600 * (weight-20));
  131.                 }
  132.                 break;
  133.            
  134.             case 8: // Surabaya
  135.                 if(weight <= 20) {
  136.                     total += 54000;
  137.                 }
  138.                 else {
  139.                     total = 54000 + (2700 * (weight-20));
  140.                 }
  141.                 break;
  142.                
  143.             case 9: // Denpasar
  144.                 if(weight <= 20) {
  145.                     total += 67000;
  146.                 }
  147.                 else {
  148.                     total = 67000 + (3350 * (weight-20));
  149.                 }
  150.                 break;
  151.            
  152.             case 10: // Salatiga
  153.                 if(weight <= 20) {
  154.                     total += 44000;
  155.                 }
  156.                 else {
  157.                     total = 44000 + (2200 * (weight-20));
  158.                 }
  159.                 break;
  160.         }
  161.        
  162.         cout << nl;
  163.         cout << "-------------------------------------" << nl;
  164.         cout << "Total berat barang\t: " << weight << " kg" << nl;
  165.         cout << "Tarif pengiriman\t: " << "Rp" << total << nl;
  166.         cout << "-------------------------------------" << nl;
  167.        
  168.         REPEAT:
  169.             cout << nl;
  170.             cout << "Ulangi? (y/n): "; cin >> next;
  171.             tolower(next);
  172.             if(next == 'n' || (next != 'y' && next != 'n')) {
  173.                 break;
  174.             }
  175.             else {
  176.                 system(clr);
  177.             }
  178.     }
  179.    
  180.     getch();
  181.     return 0;
  182. }
Tags: algo-8
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement