# How to make my overloaded fraction >> operator recognize negative numbers.

Okay, so I've been trying to get this to work for the past 2 days now, but to no avail. essentially there is a text file, from which the program extracts fractions and mixed numbers, and my >> operator is supposed to convert them to normal fractions to be outputted by my << operator, which works fine. but as soon as my function hits -8 in the file, the program crashes and ends, leaving me with the "press any key to continue" end prompt on the console. it handles -4/5 and -10/5 no problem, returning -4/5 and -2 respectively. but when the negative number is whole, it crashes.

istream& operator>>(istream& input, fraction& fr) { int Num=0; int Den=0; int Whole=0; input >> Num; if (input.peek() == '+') { Whole = Num; input.ignore() >> Num; input >> Den; } else if (input.peek() == '/') { input.ignore() >> Den; } else if (input.peek() == ' ') { input.ignore(); Den = 1; } Num = (Whole*Den) + Num; fr = fraction(Num, Den); return input; }

## Answers

Use a default of Den = 1 instead of 0. It's crashing due to divide by 0.