Rabu, 13 April 2011

contoh program c++ input kode & harga barang

#include<iostream.h>
int main()
{
char kode;
char* nama_barang;
char* harga_barang;
long int tot_harga, jumlah;

cout<<" DAFTAR NAMA BARANG BERDASARKAN KODE \n";
cout<<" *********************************** \n";
cout<<" 1: monitor, harga Rp 500000 \n";
cout<<" 2: cpu harga Rp 1000000\n";
cout<<" 3: hardisk harga Rp 400000\n";
cout<<" *********************************** \n";
cout<<"\n";

cout<<"input kode barang : ";
cin>>kode;
cout<<"input jumlah barang : ";
cin>>jumlah;

if (kode =='1' )
{
nama_barang ="monitor";
harga_barang ="500000";
tot_harga=jumlah*500000;
}

if (kode =='2' )
{
nama_barang ="cpu";
harga_barang ="1000000";
tot_harga=jumlah*1000000;
}

if (kode =='3' )
{
nama_barang ="hardisk";
harga_barang ="400000";
tot_harga=jumlah*400000;
}

cout<<"nama barang "  <<nama_barang<<endl;
cout<<"harga barang "  <<harga_barang<<endl;
cout<<"Total harga barang Rp " <<tot_harga<<endl;

return 0;
}

5 komentar: