Answers for "program sederhana pemilihan dan perulangan"

C
0

program sederhana pemilihan dan perulangan

#include <iostream.h>
#include <conio.h>
#include <stdlib.h>

void main() {
  unsigned int pilihan;
   float r, Ll, p, l, Lp, a, t, Ls;
    cout << "MENU PILIHAN" << endl;
    cout << "------------" << endl;
    cout << "1. hitung luas lingkaran" << endl;
    cout << "2. hitung luas persegi" << endl;
    cout << "3. hitung luas segitiga" << endl;
    cout << "4. exit" << endl;
    cout << "------------" << endl;

    while (pilihan>=0){
    cout << "pilihan anda (1/2/3/4)         : "; cin >> pilihan;
    switch(pilihan) {
     case 1:
      cout << "-------------------------------------"<< endl;
     cout << "Menghitung Luas Lingkaran" << endl;
      cout << "Masukan jari-jari            : "; cin >> r;
      Ll = 3.14*r*r;
     cout << "Luas Lingkaran               : " << Ll << endl;
     cout << "-------------------------------------"<< endl;
         break;
      case 2:
      cout << "-------------------------------------"<< endl;
     cout << "Menghitung Luas Persegi" << endl;
      cout << "Masukan Panjang              : "; cin >> p;
      cout << "Masukan Lebar                : "; cin >> l;
      Lp = p*l;
      cout << "Luas Persegi                 : " << Lp << endl;
     cout << "-------------------------------------"<< endl;
         break;
      case 3:
      cout << "-------------------------------------"<< endl;
     cout << "Menghitung Luas Segitiga" << endl;
      cout << "Masukan Alas                 : "; cin >> a;
      cout << "Masukan Tinggi               : "; cin >> t;
      Ls = 0.5*a*t;
      cout << "Luas Segitiga                 : " << Ls << endl;
     cout << "-------------------------------------"<< endl;
         break;
      case 4:
      exit(4);
         break;
      default:
       cout << "Kode Yang Anda Masukan Salah...!!!"<< endl;
   }
   }

  getch();
}
Posted by: Guest on January-13-2021

Code answers related to "C"

Browse Popular Code Answers by Language