#include <iostream>
using namespace std;
int harga, diskon, total;
char kode;
void totalharga(int harga, int diskon)
{
total=harga-diskon;
cout<<"Diskon "<<diskon<<", bayar : "<<total;
}
int main()
{
cout<<"Masukan harga barang : ";
cin>>harga;
cout<<"Masukan kode diskon (A-C): ";
cin>>kode;
switch(kode)
{
case 'A':
cout<<"Tidak ada diskon, harga "<<harga;
break;
case 'B':
diskon=0.1*harga;
totalharga(harga, diskon);
break;
case 'C':
diskon=0.2*harga;
totalharga(harga, diskon);
break;
default:
diskon=0.3*harga;
totalharga(harga, diskon);
break;
}
return 0;
}
#include <iostream>
using namespace std;
float bil1, bil2, hasil;
char op;
int main()
{
cout<<"Masukan bilangan pertama: ";
cin>>bil1;
cout<<"Masukan bilangan kedua: ";
cin>>bil2;
cout<<"Masukan operator (+,-,*,/): ";
cin>>op;
switch(op)
{
case '+':
hasil=bil1+bil2;
cout<<bil1<<"+"<<bil2<<"="<<hasil;
break;
case '-':
hasil=bil1-bil2;
cout<<bil1<<"-"<<bil2<<"="<<hasil;
case '*':
hasil=bil1*bil2;
cout<<bil1<<"*"<<bil2<<"="<<hasil;
case '/':
hasil=bil1/bil2;
cout<<bil1<<"/"<<bil2<<"="<<hasil;
default :
cout<<"Error operator hanya +, -, *, /";
}
return 0;
}
#include <iostream>
#include <string>
using namespace std;
string nama;
int main()
{
cout<<"Masukan nama : ";
getline(cin, nama);
cout<<"Panjang : "<<nama.length()<<" karakter.\n";
for(int i=0; i<nama.length();i++)
{
cout<<"Karakter "<<i+1<<": "<<nama[i]<<endl;
}
return 0;
}
No comments:
Post a Comment