View Single Post
Join Date: Nov 2008
Posts: 5
Reputation: kbpszs is an unknown quantity at this point 
Solved Threads: 0
kbpszs kbpszs is offline Offline
Newbie Poster

Calculating resistance

 
0
  #1
Nov 20th, 2008
Ok well my assignment is to write a program to gives me the total resistance in a circuit.
The user is prompted for the resistance type and resistor value such as <1 200> 1 meaning in series, and 200 being the value of the resistor. When the user imputs -1 for the type the program stops and gives the total resistance. 0 goes for the starting resistor, then 1 is for series, and 2 for parallel. Here is what i have so far, I know its not calculating correctly and I can understand what to do in my head, I just cant translate it to code :/ any help or suggestions would be great, thanks

An example of what a user would input would be
"Input resistance type(0 starting: 1 series: 2 parallel) and resistor value"
0 100
1 100
1 100
2 200
2 200
1 25
2 200
1 50
-1
"total resistance is" 100

  1. #include <iostream>
  2. using namespace std;
  3. int main(){
  4. int code=0; //This is the connectivity type
  5. double rv=0;//This is the resistor value
  6. double total=0;
  7. double sumD=0; //Sum of the denominator
  8.  
  9.  
  10. while (code!=-1){
  11. cout<<"Input connectivity type(0 starting: 1 series: 2 parallel) and Resistor Value:";
  12. cin>>code>>rv;
  13.  
  14. if (code==1){
  15. total += rv;}
  16. else {
  17. sumD += 1.0/rv;}
  18. }
  19. if (code==2){
  20. total += 1.0/(sumD);}
  21. cout<<total<<endl;
  22. return 0;}
Last edited by kbpszs; Nov 20th, 2008 at 3:04 am.
Reply With Quote