Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- cout << "This is a problem about calculating the whole resistance of many resistors." << endl;
- cout << "First tell me the type of connection. Press 1 for in series connection or 2 for parallel connection." << endl;
- int option;
- cin >> option;
- cout << "Now give me how many resistors you want to connect in this type." << endl;
- int n;
- cin >> n;
- float rwhole=0;
- float c;
- switch(option){
- case 1:
- cout << "You chose in series connection." <<endl;
- for(int i=0; i<n; i++){
- cout << "Give the value (in Ohm) of resistor number" << i+1 << ":" <<endl;
- float r1;
- cin >> r1;
- rwhole+=r1;
- }
- cout << "The whole resistance of the" << n << "resistors in series is: R=" << rwhole << " Ohm." << endl;
- break;
- case 2:
- cout << "You chose parallel connection." << endl;
- for (int j=0; j<n; j++){
- cout << "Give me the value (in Ohm) of resistor number" << j+1 << ":" << endl;
- float r2;
- cin >> r2;
- c+= 1/r2;
- }
- rwhole= 1/c;
- cout << "The whole resistance of the" << n << "resistors in parallel connection is: R=" << rwhole << " Ohm." << endl;
- break;
- default:
- cout << "No option for pressing " << option << "." << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement