title: Separating denominator and numerator inputs when given a slash c++
body: <p>Im relatively new to C++ and I was wondering if I could get help with a problem that ive been having. Im given an input as either a fraction of type A/B or an integer value. I need to separate the A and B values so I can put them in the fracnum and fracdnum variables. The problem comes when im given an integer value. Here is my code:</p>
  
  <pre><code>istream&amp; operator &gt;&gt;(istream&amp; in,  Fraction&amp; frac){
      char slash = '/' ;
      int fracnum;
      int fracdnum;
      int peekchar;
  in &gt;&gt;fracnum;
  if(in &gt;&gt; slash){
      in &gt;&gt;fracdnum;
  }
  else{
      in.putback(slash);
      fracdnum = 1;
  }
  
      frac = Fraction(fracnum, fracdnum);
      return in;
      }
  </code></pre>
  
  <p>I do not know how to split the two fractions and also handle integers.</p>
  
  <p>edit*****</p>
  
  <p>Ive tried using the scanf method but it still isnt working, here is my try at it, anybody notice anything wrong with it? </p>
  
  <pre><code>istream&amp; operator &gt;&gt;(istream&amp; in,  Fraction&amp; frac){
  int fracdnum;
  int fracnum;
  int num_read = scanf("%d/%d", &amp;fracnum, &amp;fracdnum);
  if( num_read ==1){
      fracdnum=1;
  Fraction(fracnum,fracdnum);
  }
  else if (num_read == 2){
      Fraction(fracnum,fracdnum);
  }
  
      return in;
      }
  </code></pre>
  
  <p>This is the test file i use for the program:</p>
  
  <pre><code>    // Test input, exception and +=:
      Fraction sum(0);
      Fraction fin;
      cout &lt;&lt; "\nSumming fractions. Enter fractions as \"1/2\" or just enter a single integer." &lt;&lt; endl;
      cout &lt;&lt; "Enter zero to end the summation:" &lt;&lt; endl;
      do {
          cout &lt;&lt; "Enter a fraction to add to sum: ";
          try {
              cin &gt;&gt; fin;
              sum += fin;
          } catch (FractionException &amp;e) {
              cout &lt;&lt; e.what() &lt;&lt; endl;
          }
      } while (fin != 0);
      cout &lt;&lt; "Sum is: " &lt;&lt; sum &lt;&lt; endl;
  
  
      return 0;
  
  } // end main
  </code></pre>