Jump to content
Sign in to follow this  
atyasl reza

Tolong Saya Betulkan Yg Nih...esok Dah Nak Antar Ni...help Me...

Recommended Posts

/* Tuliskan aturcara C++ yang lengkap bagi melaksanakan perkara-perkara
dibawah:

Diberi jadual seperti dibawah:

Kod Jenis Minuman Harga
===========================
1 Milo Rm 1.50
2 Kopi Rm 1.00
3 Coca Cola Rm 1.20
4 Jus Oren Rm 1.80

Kod minuman perlu diinputkan. Jenis minuman beserta harga akan dipaparkan.
Paparkan dalam format yang anda fikirkan sesuai. Sekiranya jumlah melebihi
100, potongan sebanyak 15% akan diberkan, sebaliknya tiada potongan
diberkan. */

#include<iostream.h>

int nKod;
int nKuantiti;
float fJumlah;
float fDiskaun;

void main()
{
cout<<"Masukkan kod minuman:";
cin>>nKod;
cout<<"Masukkan kuantiti:";
cin>>nKuantiti;

if(nKod == 1)
{
cout<<"Jenis minuman: Milo Harga: Rm 1.50"<<endl;
fJumlah = 1.5 * nKuantiti;
}

else if(nKod == 2)
{
cout<<"Jenis minuman: Kopi Harga: Rm 1.00"<<endl;
fJumlah = 1.00 * nKuantiti;
}

else if(nKod == 3)
{
cout<<"Jenis minuman: Coca-Cola Harga: Rm 1.20"<<endl;
fJumlah = 1.2 * nKuantiti;
}

else if(nKod == 4)
{
cout<<"Jenis minuman: Jus Oren Harga: Rm 1.80"<<endl;
fJumlah = 1.8*nKuantiti;
}

else
cout<<"----Out of range----";


if(fJumlah > 100)
{
fDiskaun = fJumlah * 0.15;
fJumlah = fJumlah - fDiskaun;
cout<<"Harganya bagi kuantiti sebanyak %d ialah RM %.2f\n", nKuantiti, fJumlah;
}

else
cout<<"Harganya bagi kuantiti sebanyak %d ialah RM %.2f\n", nKuantiti, fJumlah;

}

Share this post


Link to post
Share on other sites
[code]fJumlah = xxxx * nKuantiti; [/code]

Janganlah digabungkan setiap item punya nilai memang la dapat 1 nilai je.

Buat variable untuk setiap item kemudian hujung sekali baru jumlahkan.

Share this post


Link to post
Share on other sites
er tt x de apa2 error pun kad program ko.
ni aku ada auta sikit part yg bawah tu.
100% working.

[code]
#include<iostream.h>

int nKod;
int nKuantiti;
float fJumlah;
float fDiskaun;

void main()
{
cout<<"Masukkan kod minuman:";
cin>>nKod;
cout<<"Masukkan kuantiti:";
cin>>nKuantiti;

if(nKod == 1)
{
cout<<"Jenis minuman: Milo Harga: RM 1.50"<<endl;
fJumlah = 1.5 * nKuantiti;
}

else if(nKod == 2)
{
cout<<"Jenis minuman: Kopi Harga: RM 1.00"<<endl;
fJumlah = 1.00 * nKuantiti;
}

else if(nKod == 3)
{
cout<<"Jenis minuman: Coca-Cola Harga: RM 1.20"<<endl;
fJumlah = 1.2 * nKuantiti;
}

else if(nKod == 4)
{
cout<<"Jenis minuman: Jus Oren Harga: RM 1.80"<<endl;
fJumlah = 1.8*nKuantiti;
}

else

cout<<"----Out of range----";


if(fJumlah > 100)
{
fDiskaun = fJumlah * 0.15;
fJumlah = fJumlah - fDiskaun;
cout<<"Harganya bagi kuantiti sebanyak "<<nKuantiti<<" ialah RM "<<fJumlah<<endl;
}

else
cout<<"Harganya bagi kuantiti sebanyak "<<nKuantiti<<" ialah RM "<<fJumlah<<endl;
}
[/code] Edited by otai_g

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...