Anda di halaman 1dari 7

#include <iostream>

using namespace std;

//mencoba percabangan dan pengulangan

int main()

int a,e,i;

cout<< "Mesin Penghitung"<< endl;

cout<< "__________________________________________"<<endl;

cout<< "Pilihan anda \n"<< endl;

cout<< "1. Penjumlahan"<< endl;

cout<< "2. Pengurangan"<< endl;

cout<< "3. Perkalian"<< endl;

cout<< "4. Pembagian"<< endl;

cout<< "5. Menghitung Bangun Datar (cm)"<< endl;

cout<< "6. Exit \n"<< endl;

cout<< "pilihan (1/2/3/4/5/6) :";

cin >> a;

if (a==1){

cout<<"_________________________________________"<<endl;

cout<< "Penjumlahan\n"<<endl;

float b,c;

cout<<"masukan nilai pertama :";cin >>b ;


cout<<"masukan nilai kedua :";cin >>c ;

float d=b+c;

cout<<"Hasil :"<<d;

else if(a==2){

cout<<"_________________________________________"<<endl;

cout<<"Pengurangan\n"<<endl;

float b,c;

cout<<"masukan nilai pertama :"; cin >>b;

cout<<"masukan nilai kedua :"; cin >>c;

float d=b-c;

cout<< "Hasil : "<<d;

else if(a==3){

cout<<"_________________________________________"<<endl;

cout<<"Perkalian\n"<<endl;

float b,c;

cout<<"masukan nilai pertama :"; cin >>b;

cout<<"masukan nilai kedua :"; cin >>c;

float d=b*c;

cout<<"Hasil :"<<d;

else if(a==4){

cout<<"_________________________________________"<<endl;

cout<<"Pembagian\n"<<endl;
float b,c;

cout<<"masukan nilai pertama :"; cin >>b;

cout<<"masukan nilai kedua :"; cin >>c;

float d=b/c;

cout<<"Hasil :"<<d;

else if(a==5){

cout<<"_________________________________________"<<endl;

cout<<"Menghitung Bangun Datar\n"<<endl;

cout<<"1.Persegi"<<endl;

cout<<"2.Persegi Panjang"<<endl;

cout<<"3.Segitiga"<<endl;

cout<<"4.Linkaran\n"<<endl;

cout<<"Pilihan (1/2/3/4) :";cin >> e;

if(e==1){

cout<<"_________________________________________"<<endl;

cout<<"Persegi\n"<<endl;

cout<<"1.Keliling Persegi"<<endl;

cout<<"2.Luas Persegi\n"<<endl;

cout<<"Pilihan (1/2/) :";cin >>i;

if(i==1){

cout<<"_________________________________________"<<endl;

cout<<"Keliling Persegi\n"<<endl;

float s;

cout<<"Masukan nilai sisi :"; cin >>s;


float k=4*s;

cout<<"Keliling :"<<k<<" cm";

else if(i==2){

cout<<"_________________________________________"<<endl;

cout<<"Luas Persegi\n"<<endl;

float s;

cout<<"Masukan nilai sisi :"; cin >>s;

float l=s*s;

cout <<"Luas :"<<l<<" cm2";

if(e==2){

cout<<"_________________________________________"<<endl;

cout<<"Persegi Panjang\n"<<endl;

cout<<"1.Keliling Persegi Panjang"<<endl;

cout<<"2.Luas Persegi Panjang\n"<<endl;

cout<<"Pilihan (1/2/) :";cin >>i;

if(i==1){

cout<<"_________________________________________"<<endl;

cout<<"Keliling Persegi Panjang\n"<<endl;

float p,l;

cout<<"Masukan nilai panjang :"; cin >>p;

cout<<"Masukan nilai lebar :"; cin >>l;

float k=(p+l)*2;
cout<<"Keliling :"<<k<<" cm";

else if(i==2){

cout<<"_________________________________________"<<endl;

cout<<"Luas Persegi Panjang\n"<<endl;

float p,l;

cout<<"Masukan nilai panjang :"; cin >>p;

cout<<"Masukan nilai lebar :"; cin >>l;

float Luas=p*l;

cout <<"Luas :"<<Luas<<" cm2";

if(e==3){

cout<<"_________________________________________"<<endl;

cout<<"Segitiga\n"<<endl;

cout<<"1.Keliling Segitiga"<<endl;

cout<<"2.Luas Segitiga\n"<<endl;

cout<<"Pilihan (1/2/) :";cin >>i;

if(i==1){

cout<<"_________________________________________"<<endl;

cout<<"Keliling Segitiga\n"<<endl;

float a,b,c;

cout<<"Masukan nilai sisi1 :"; cin >>a;

cout<<"Masukan nilai sisi2 :"; cin >>b;

cout<<"Masukan nilai sisi3 :"; cin >>c;


float k=a+b+c;

cout<<"Keliling :"<<k<<" cm";

else if(i==2){

cout<<"_________________________________________"<<endl;

cout<<"Luas Segitiga\n"<<endl;

float a,t;

cout<<"Masukan nilai alas :"; cin >>a;

cout<<"Masukan nilai tinggi :"; cin >>t;

float Luas=(a*t)/2;

cout <<"Luas :"<<Luas<<" cm2";

if(e==4){

cout<<"_________________________________________"<<endl;

cout<<"Lingkaran\n"<<endl;

cout<<"1.Keliling Lingkaran"<<endl;

cout<<"2.Luas Lingkaran\n"<<endl;

cout<<"Pilihan (1/2/) :";cin >>i;

if(i==1){

cout<<"_________________________________________"<<endl;

cout<<"Keliling Lingkaran\n"<<endl;

float r;

cout<<"Masukan nilai jari-jari :"; cin >>r;

float k=2*3.14*r;
cout<<"Keliling :"<<k<<" cm";

else if(i==2){

cout<<"_________________________________________"<<endl;

cout<<"Luas lingkaran\n"<<endl;

float r;

cout<<"Masukan nilai jari-jari :"; cin >>r;

float Luas=3.14*r*r;

cout <<"Luas :"<<Luas<<" cm2";

else if(a==6){

exit(6);

else {

cout<<"code yang anda masukan salah!";