0% found this document useful (0 votes)
35 views

Array (Part One)

This document provides a code sample to demonstrate using arrays in an if statement logic to calculate travel package prices. The code defines arrays to store package codes, destinations, prices, quantities purchased, and total prices. It prompts the user to enter a customer name, number of packages, and details for each package. It then calculates subtotals, totals, amounts paid, and change returned. The program outputs the input data and purchase summary.

Uploaded by

Gilang Maulana
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views

Array (Part One)

This document provides a code sample to demonstrate using arrays in an if statement logic to calculate travel package prices. The code defines arrays to store package codes, destinations, prices, quantities purchased, and total prices. It prompts the user to enter a customer name, number of packages, and details for each package. It then calculates subtotals, totals, amounts paid, and change returned. The program outputs the input data and purchase summary.

Uploaded by

Gilang Maulana
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

Latihan Array – If

Buat tampilan input seperti berikut

Setelah di input maka akan menampilkan output seperti berikut

Logika program
Gunakan array pada penginputan data paket
Kode Paket Tujuan Paket Harga Paket
1 Jakarta - Bandung Rp 700000
2 Jakatra - Lombok Rp 3000000
3 Jakarta – Bali Rp 5000000

Maulana Gilang 1
#include<stdio.h>
#include<conio>
#include<iostream>
main()
{
int i,banyak,kdpaket[10],jumbel[10];
long int harga[10],tohar[10],bayar,tobay=0,kembali,total[10];
char tujpaket[10][25],napel[15];
cout<<"\t\tMr. Okem Travel's"<<endl;
cout<<"^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"<<endl;
cout<<"Nama Pelanggan : ";gets(napel);
cout<<"Banyaknya Beli : ",cin>>banyak;
for (i=1;i<=banyak;i++)
{
cout<<"Data ke "<<i<<endl;
cout<<"Kode Paket : ";cin>>kdpaket[i];
if (kdpaket[i]==1)
{
strcpy(tujpaket[i],"Jakarta - Bandung ");
harga[i]=700000;
}
else if (kdpaket[i]==2)
{
strcpy(tujpaket[i],"Jakarta - Lombok ");
harga[i]=3000000;
}
else
{
strcpy(tujpaket[i],"Jakarta - Lombok ");
harga[i]=5000000;
}
cout<<"Tujuan Travel : "<<tujpaket[i]<<endl;
cout<<"Harga Paket : "<<harga[i]<<endl;
cout<<"Jumlah Beli : ";cin>>jumbel[i];
tohar[i]=jumbel[i]*harga[i];
cout<<"Total Harga : "<<tohar[i]<<endl;
tobay=tobay+tohar[i];
}
cout<<endl<<endl;
clrscr();
cout<<"\t\tMr. Okem Travel's"<<endl;
cout<<"^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"<<endl;
cout<<"Nama Pelanggan : "<<napel<<endl;
cout<<"Total Bayar : "<<tobay<<endl;
cout<<"Bayar : ";cin>>bayar;
kembali=bayar-tobay;
cout<<"Uang Kembali : "<<kembali<<endl;
cout<<"^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"<<endl;
cout<<"Terima Kasih Atas kepercayaan anda melakukan transaksi";
getch();

Maulana Gilang 2

You might also like