title: Parallel Circuit
body: <p>I am having trouble with this programming assignment. I need to calculate the value of total resistance for a parallel and series circuit. I have the series circuit functioning, but my problem is that when I try to calculate the total resistance for parallel circuit, my return value is 1.#INF. Any suggestions to how I can fix this</p>
  
  <pre><code>    // project.cpp : Defines the entry point for the console application.
      //
  
      #include "stdafx.h"
      #include &lt;iostream&gt;
      #include &lt;math.h&gt;
  
      using namespace std;
  
      void menu()
      {
         cout &lt;&lt;"\t\t\tLab 2 Menu Driven Algorithms" &lt;&lt; endl;
         cout &lt;&lt;"\t\t  Calculating Parallel and Series Resistance" &lt;&lt; endl;
         cout &lt;&lt;"1)\tSeries" &lt;&lt; endl;
         cout &lt;&lt;"2)\tParallel" &lt;&lt; endl;
         cout &lt;&lt;"3)\tQuit" &lt;&lt; endl;   
      }
  
      int series(int&amp; num, int&amp; sum)
      {
  int answer;
  num = 0;
  sum = 0;
  
  do
  {
      cout &lt;&lt; "Enter Resistor " &lt;&lt; num+1 &lt;&lt; " value, 0 to calculate: ";
      cin &gt;&gt; answer;
      cout &lt;&lt; endl;
  
      sum = sum + answer;
  
      num++;
  }
  while(answer != 0);     
  
  return sum;
      }
  
      double parallel (int&amp; num, double&amp; sum)
      {
  double answer;
  num = 0;
  sum = 0.0;
  int counter = 0;
  
  do
  {
      cout &lt;&lt; "Enter Resistor " &lt;&lt; num+1 &lt;&lt; " value, 0 to calculate: ";
      cin &gt;&gt; answer;
      cout &lt;&lt; endl;
      counter++;
  
      sum = (1/answer) + sum;
      cout &lt;&lt; sum &lt;&lt; endl;
  
      num++;
  }
  while(answer != 0);
  
  return sum;
      }
  
  
  
  
      int main()
      {
  char choice;
  int num = 0;
  int sum = 0;
  double sum2 = 0.0;
  
  menu();
  
  cout &lt;&lt;"\n\nPlease enter a value from the menu: ";
  cin &gt;&gt; choice;
  cout &lt;&lt; endl;
  
  while (choice != '3' &amp;&amp; choice != 'q' &amp;&amp; choice != 'Q')
  {
  
  
  switch(choice)
  {
      case '1': cout &lt;&lt; "Calculating Series Resistance" &lt;&lt; endl;
                cout &lt;&lt; "The series resistance for the " &lt;&lt; num-1 &lt;&lt; " resistors is: " &lt;&lt; series(num, sum) &lt;&lt; " Ohms\n";
                system("pause");
                break;
      case '2': cout &lt;&lt; "Calculating Parallel Resistance" &lt;&lt; endl;
                cout &lt;&lt; "The parallel resistance for the " &lt;&lt; num-1 &lt;&lt; " resistors is: " &lt;&lt; parallel(num, sum2) &lt;&lt; " Ohms\n";
                system("pause");
                break;
      default: break;
  
  }
  
  system("cls");
  
  menu();
  
  cout &lt;&lt;"\n\nPlease enter a value from the menu: ";
  cin &gt;&gt; choice;
  cout &lt;&lt; endl;
  
  
  } 
  system("pause");
  
  return 0;
      }
  </code></pre>