#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{
A:
char pilihan,lagi;
unsigned int r_ke,jml_r,nilai_r;
float r_tot;
unsigned int i=0;
float n[i];
float prev[i];
cout << "\n>>> PROGRAM MENGHITUNG NILAI RESISTOR <<<" << endl;
cout << ">>> SERI DAN PARALEL <<<" << endl;
cout << "\n\n=============== Menu Pilihan ================" << endl;
cout << "\n Masukan Pilihan! \n" << endl;
cout << "\tA: Menghitung Resistor Seri " << endl;
cout << "\tB: Menghitung Resistor Paralel" << endl;
cout << "\nPilih = ";
cin >> pilihan;
cout << "\n";
if(pilihan=='a' || pilihan=='A'){
cout << "Bayak Resistor dalam rangkaian SERI : ";
cin >> jml_r;
if(jml_r<=1){
cout << "INPUT ERROR\n\n";
return 0;
}
cout << "\n";
for(r_ke=1;r_ke<=jml_r;r_ke++){
cout << "Nilai Resistor Ke-" <<r_ke; cout << " = ";
cin >> nilai_r;
n[r_ke]=nilai_r;
}
prev[1]=n[1];
for(i=1;i<jml_r;i++){
r_tot=prev[i]+n[i+1];
prev[i+1]=r_tot;
}
cout << "\nNilai Resistor Total : " << r_tot;
cout << "\n\n\n\n\n\n";
}
else if(pilihan=='b' || pilihan=='B'){
cout << "Bayak Resistor dalam rangkaian PARALEL : ";
cin >> jml_r;
if(jml_r<=1){
cout << "INPUT ERROR\n\n";
return 0;
}
cout << "\n";
for(r_ke=1;r_ke<=jml_r;r_ke++){
cout << "Nilai Resistor Ke-" <<r_ke; cout << " = ";
cin >> nilai_r;
n[r_ke]=nilai_r;
}
prev[1]=n[1];
for(i=1;i<jml_r;i++){
r_tot=1/((1/prev[i]) + (1/n[i+1]));
prev[i+1]=r_tot;
}
cout << "\nNilai Resistor Total : " << r_tot; cout << " ohm";
cout << "\n\n\n\n\n";
}
else if(pilihan!='b' || pilihan!='B' || pilihan!='a' || pilihan!='A'){
cout << "Pilihan tidak VALID!" << endl;
}
cout << " Hitung Lagi? " <<endl;
cout << " Ya(y) Tidak(t)" <<endl;
cout <<"\njawab :"; cin >> lagi;
if(lagi=='y'||lagi=='Y'){
system("cls");
goto A;
}
else if(lagi=='t'||lagi=='T'){
cout << "\n\n\n";
return 0;
}
return 0;
}
3 komentar
Click here for komentarkalau misal untuk yang ragkaian kombinasi itu bagaimana ya mas
ReplyFungsi dr perintah prev[1] = n[1] buat apa ya mas?
Replykenapa float n dan float prev saya eror
ReplyConversionConversion EmoticonEmoticon