+ 1

Please help for this, what is this wrong ?

#include <iostream> #include <conio.h> using namespace std; int main() { int iKode, iHarga, cJenis; cout<<"Jenis Barang : "; cin>>cJenis; cout<<endl; cout<<"Kode Barang : "; cin>>iKode; cout<<endl; cout<<"Harga Barang : "; cin>>iHarga; cout<<endl; int (cJenis: character); swicth(cJenis); { case A: cout<<(iHDiskon=0,9*iHarga); break; case B: cout<<(iHDiskon=0,85*iHarga); break; } getch(); }

7th Apr 2018, 4:58 PM
Muhammad Aulia Baramuli Lubis
Muhammad Aulia Baramuli Lubis - avatar
13 Answers
+ 2
@Muhammad Aulia Baramuli Lubis, Here, I updated the example with comments in Bahasa Indonesia, I hope this can explain the code bro. #include <iostream> using namespace std; int main() { int iKode, iHarga; char cJenis; // tipe data char hanya bisa menampung // 1 karakter/huruf, sedangkan 'dasi' ada // 4 huruf, ini sebabnya input 'dasi' // tapi hanya 'd' yang tersimpan (1 huruf). // Untuk mencoba kode ini input untuk // cJenis bisa 'A', 'B', 'C', jika input // selain itu harga diskon nol karena // switch statement hanya // membandingkan 'A', 'B' atau 'C'. cout << "Jenis Barang : "; cin >> cJenis; cout << cJenis; cout << endl; cout << "Kode Barang : "; cin >> iKode; cout << iKode; cout << endl; cout << "Harga Barang : "; cin >> iHarga; cout << iHarga; cout << endl; // variable harga dipotong diskon int iHDiskon {0}; // switch membandingkan value dalam // variable cJenis. Jika nilainya : // 'A' diskon 10%, // 'B' diskon 15% // 'C' diskon 20% switch(cJenis) { case 'A': iHDiskon = 0.9 * iHarga; break; case 'B': iHDiskon = 0.85 * iHarga; break; case 'C': iHDiskon = 0.8 * iHarga; break; } // Output harga diskon cout << "\nHarga Diskon: " << iHDiskon; return 0; } P.S. There is no need for conio.h in program, it is not recommended to use conio.h : ) https://www.sololearn.com/Discuss/1185370/?ref=app
7th Apr 2018, 10:50 PM
Ipang
+ 1
#include <iostream> #include <conio.h> #include <iomanip> using namespace std; int main() //NAMA : MUHAMMAD AULIA BARAMULI LUBIS //NIM : 171011401536 //PROGRAM STUDY : TEKNIK INFORMATIKA //SEMESTER : II (GENAP) / 2017-2018 { int iKode, iHarga; char cJenis; cout<<endl <<"==========HARGA DISKON==========" <<endl <<endl; //Masukan Data cout<<"Kode Barang : "; cin>>iKode; cout<<endl; cout<<"Jenis Barang : "; cin>>cJenis; cout<<endl; cout<<"Harga Barang : "; cin>>iHarga; cout<<endl; int iHDiskon {0}; switch(cJenis) { case 'A': iHDiskon = 0.9 * iHarga; break; case 'B': iHDiskon = 0.85 * iHarga; break; case 'C': iHDiskon = 0.8 * iHarga; break; } cout<<"================================" <<endl; //Cetak Harga cout<<endl <<"Harga Setelah Di Diskon : " <<iHDiskon <<" Rupiah" <<endl <<endl <<"==========TERIMA KASIH==========" <<endl; return 0; }
7th Apr 2018, 10:42 PM
Muhammad Aulia Baramuli Lubis
Muhammad Aulia Baramuli Lubis - avatar
0
You spelled switch wrong?
7th Apr 2018, 5:12 PM
Ariela
Ariela - avatar
0
i already revice it, but not yet also
7th Apr 2018, 6:11 PM
Muhammad Aulia Baramuli Lubis
Muhammad Aulia Baramuli Lubis - avatar
0
#include <iostream> #include <conio.h> using namespace std; int main() { int iKode, iHarga, cJenis; cout<<"Jenis Barang : "; cin>>cJenis; cout<<endl; cout<<"Kode Barang : "; cin>>iKode; cout<<endl; cout<<"Harga Barang : "; cin>>iHarga; cout<<endl; switch(cJenis); { case A: cout<<(iHDiskon=0,9*iHarga); break; case B: cout<<(iHDiskon=0,85*iHarga); break; } getch(); }
7th Apr 2018, 6:15 PM
Muhammad Aulia Baramuli Lubis
Muhammad Aulia Baramuli Lubis - avatar
0
thank you bro, i already try this but, not yet answer from my job
7th Apr 2018, 6:29 PM
Muhammad Aulia Baramuli Lubis
Muhammad Aulia Baramuli Lubis - avatar
0
Jenis Barang : dasi d Kode Barang : 0 Harga Barang : 0 Kode: 0 Jenis: d Harga: 0 Harga Diskon: 0 -------------------------------- Process exited after 9.892 seconds with return value 0 Press any key to continue . . . if runing, this result
7th Apr 2018, 6:32 PM
Muhammad Aulia Baramuli Lubis
Muhammad Aulia Baramuli Lubis - avatar
0
no, i input "dasi" from input jenis barang
7th Apr 2018, 6:40 PM
Muhammad Aulia Baramuli Lubis
Muhammad Aulia Baramuli Lubis - avatar
0
i want make program from this algoritma : Algoritma Menghitung Barang Kamus Data iKode,iHarga:integer cJenis: character Begin input(cJenis) input(iKode) input(iHarga) case(Jenis) 'A': iHDiskon=0,9*iHarga 'B': iHDiskon=0.85*iHarga 'C': iHDiskon=0,8*iHarga end case output(iHDiskon) end
7th Apr 2018, 6:51 PM
Muhammad Aulia Baramuli Lubis
Muhammad Aulia Baramuli Lubis - avatar
0
i must create program to clearing case as below : program can take input form : "kode", "jenis", "harga" with type : "A", "B", "C" for every type will give diskon : "A" diskon 10% "B" diskon 15% "C" diskon 20% program must calculation price after diskon example input : Jenis = B , kode = 10 , harga = 10000 example output : jenis barang B take dikon = 15%, price afer diskon = 8500
7th Apr 2018, 8:46 PM
Muhammad Aulia Baramuli Lubis
Muhammad Aulia Baramuli Lubis - avatar
0
oke done i already understand
7th Apr 2018, 10:42 PM
Muhammad Aulia Baramuli Lubis
Muhammad Aulia Baramuli Lubis - avatar
0
==========HARGA DISKON========== Kode Barang : 1 Jenis Barang : A Harga Barang : 10000 ================================ Harga Setelah Di Diskon : 9000 Rupiah ==========TERIMA KASIH========== -------------------------------- Process exited after 9.693 seconds with return value 0 Press any key to continue . . .
7th Apr 2018, 10:44 PM
Muhammad Aulia Baramuli Lubis
Muhammad Aulia Baramuli Lubis - avatar
0
oke bro thank you very much
7th Apr 2018, 10:45 PM
Muhammad Aulia Baramuli Lubis
Muhammad Aulia Baramuli Lubis - avatar