Create a script with if, else if, and else conditionals to calculate the Total R
ID: 1715584 • Letter: C
Question
Create a script with if, else if, and else conditionals to calculate the Total Resistance (R_T) 1) r1 , r2, and r3 are connected in series manner. (R_T= r1+r2+r3) 2) r1, r2, and r3 are connected in parallel manner.(R_T = 1/((1/r1)+(1/r2)+(1/r3)) ) 3) r1 is connected to the parallelly connected r2 and r3 in series manner. (R_T = r1 + r2xr3/(r2+r3) ) The output should be The Total Resistance is [your result] ohms since r1, r2, r3 are connected in [series, parallel, combination] manner. r1 = 10 , r2 = 20 , and r3 = 30 . 2. Repeat problem 1. This time use “switch”.
Please answer using the "DEV C++" software.
Explanation / Answer
// Solution :
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
double res,r1,r2,r3 ;
int n, c;
cout << "Enter the type of combination in the circuit:0 for Series , 1 for parallel , 2 for series parallel ";
cin >> c;
cout << "Enter the resistances in OHM ";
cin >> r1>>r2>>r3;
if(c==0)res=r1+r2+r3;
if(c==1)res=(r1*r2*r3)/(r1*r2+r2*r3+r3*r1);
if(c==2)res=r1+((r2*r3)/(r2+r3));
cout << "The Total Resistance is : =" <<res;
return 1;
}
// code ends here-------------------------------------------------------------
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
double res,r1,r2,r3 ;
int n, c;
cout << "Enter the type of combination in the circuit:0 for Series , 1 for parallel , 2 for series parallel ";
cin >> c;
cout << "Enter the resistances in OHM ";
cin >> r1>>r2>>r3;
switch(c) {
case 0 :res=r1+r2+r3;
break;
case 1: res=(r1*r2*r3)/(r1*r2+r2*r3+r3*r1);
break;
case 2 :res=r1+((r2*r3)/(r2+r3));
break;
}
cout << "The Total Resistance is : =" <<res;
return 1;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.