Advertisement
makispaiktis

Resistors

Mar 22nd, 2018 (edited)
448
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.47 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.  
  8.    cout << "This is a problem about calculating the whole resistance of many resistors." << endl;
  9.    cout << "First tell me the type of connection. Press 1 for in series connection or 2 for parallel connection." << endl;
  10.    int option;
  11.    cin >> option;
  12.  
  13.  
  14.    cout << "Now give me how many resistors you want to connect in this type." << endl;
  15.    int n;
  16.    cin >> n;
  17.  
  18.    float rwhole=0;
  19.    float c;
  20.  
  21.    switch(option){
  22.  
  23.      case 1:
  24.      cout << "You chose in series connection." <<endl;
  25.  
  26.       for(int i=0; i<n; i++){
  27.             cout << "Give the value (in Ohm) of resistor number" << i+1 << ":" <<endl;
  28.             float r1;
  29.             cin >> r1;
  30.             rwhole+=r1;
  31.                                 }
  32.      cout << "The whole resistance of the" << n << "resistors in series is: R=" << rwhole << " Ohm." << endl;
  33.      break;
  34.  
  35.  
  36.      case 2:
  37.      cout << "You chose parallel connection." << endl;
  38.  
  39.        for (int j=0; j<n; j++){
  40.              cout << "Give me the value (in Ohm) of resistor number" << j+1 << ":" << endl;
  41.              float r2;
  42.              cin >> r2;
  43.              c+= 1/r2;
  44.                                    }
  45.  
  46.        rwhole= 1/c;
  47.        cout << "The whole resistance of the" << n << "resistors in parallel connection is: R=" << rwhole << " Ohm." << endl;
  48.        break;
  49.  
  50.  
  51.      default:
  52.      cout << "No option for pressing " << option << "." << endl;
  53.    }
  54.  
  55.    return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement