#include <iostream>
int main()
{
int n, op;
std::cout << "Enter the number of conductors" << std::endl;
std::cin >> n;
std::cout << "Enter operation (1 for serial or 2 for parallel)" << std::endl;
std::cin >> op;
double R = 0.0;
switch (op)
case 1:
for (int i = 0; i < n; ++i)
std::cout << "Enter the resistance of a " << i + 1 << " conductor" << std::endl;
double temp;
std::cin >> temp;
R += temp;
}
break;
case 2:
R += 1 / temp;
R = 1 / R;
default:
std::cout << "Unknown operation!" << std::endl;
std::cout << "R == " << R << std::endl;
system("pause");
return 0;
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
#include <iostream>
int main()
{
int n, op;
std::cout << "Enter the number of conductors" << std::endl;
std::cin >> n;
std::cout << "Enter operation (1 for serial or 2 for parallel)" << std::endl;
std::cin >> op;
double R = 0.0;
switch (op)
{
case 1:
{
for (int i = 0; i < n; ++i)
{
std::cout << "Enter the resistance of a " << i + 1 << " conductor" << std::endl;
double temp;
std::cin >> temp;
R += temp;
}
break;
}
case 2:
{
for (int i = 0; i < n; ++i)
{
std::cout << "Enter the resistance of a " << i + 1 << " conductor" << std::endl;
double temp;
std::cin >> temp;
R += 1 / temp;
}
R = 1 / R;
break;
}
default:
std::cout << "Unknown operation!" << std::endl;
break;
}
std::cout << "R == " << R << std::endl;
system("pause");
return 0;
}