Selasa, 30 Juni 2015

C++ Program Rangkaian Listrik ( switch-case )

C++ Program Rangkaian Listrik ( switch-case )

#include <iostream>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;

int main(int argc, char *argv[]) {

/*Dibaca tiga tahanan R1, R2 dan R3, kemudian tampilkan hambatan seri total (RS) atau hambatan paralel total (RP).
jika input "1" maka tampilkan RS, jika input "2" maka tampilkan RP. jika tidak keduanya maka keluar program.*/

int menu;
float R1, R2, R3, RS, RP;
           
cout<<"===========================================\n";
cout<<"| <<<<<  Program Rangkaian Listrik  >>>>> |\n";
cout<<"===========================================\n\n";
cout<<"Pilihan : \n";
cout<<"1. Hitung hambatan seri total (RS) \n";
cout<<"2. Hitung hambatan paralel total (RP)\n";
cout<<"3. Not Found \n\n";
cout<<"Masukkan pilihan Anda [1/2/3 ?] : ";
cin>>menu;

switch(menu){
case 1:
cout<<"Masukkan nilai resistor 1 (R1) : ";
cin>>R1;
cout<<"\nMasukkan nilai resistor 2 (R2) : ";
cin>>R2;
cout<<"\nMasukkan nilai resistor 3 (R3) : ";
cin>>R3;
RS=R1+R2+R3;
cout<<"Hambatan seri total = "<<RS<<" ohm";
break;
case 2:
cout<<"Masukkan nilai resistor 1 (R1) : ";
cin>>R1;
cout<<"\nMasukkan nilai resistor 2 (R2) : ";
cin>>R2;
cout<<"\nMasukkan nilai resistor 3 (R3) : ";
cin>>R3;
RP=(1/(1/R1+1/R2+1/R3));
cout<<"Hambatan paralel total = "<<RP<<" ohm";
break;
case 3 :
cout<<"Not Found ";
break;
default:
cout<<" ";
break;
}
return 0;
}

HASIL COMPILE :




Related Posts:

  • C++ PROGRAM PERSAMAAN KUADRAT C++ PROGRAM PERSAMAAN KUADRAT  #include <iostream> #include <math.h> /* run this program using the console pauser or add your own getch, system("pause") or input loop */ using namespace std; int main(int ar… Read More
  • C++ Program Jam Digital (tanpa CLASS )Program Jam Digital Bahasa C++ ( tanpa CLASS ) #include <iostream> #include <ctime> #include <cstdlib> #include <windows.h> /* run this program using the console pauser or add your own getch, system("… Read More
  • C++ Program JAM DIGITAL ( CLASS )Program JAM DIGITAL bahasa C++ menggunakan CLASS #include <iostream> #include <ctime> #include <cstdlib> #include <windows.h> /* run this program using the console pauser or add your own getch, system… Read More
  • C++ PROGRAM BILANGAN (terbesar, terkecil, rerata)C++ PROGRAM BILANGAN (terbesar, terkecil, rerata) #include <iostream> /* run this program using the console pauser or add your own getch, system("pause") or input loop */ using namespace std; int main(int argc, char … Read More
  • C++ PROGRAM MENCARI BILANGAN TERBESAR DAN TERKECIL ( CLASS ) C++ PROGRAM MENCARI BILANGAN TERBESAR DAN TERKECIL  ( CLASS ) #include <iostream> #include <cstdlib> using namespace std; /* run this program using the console pauser or add your own getch, system("pause") o… Read More

0 komentar:

Posting Komentar