Date: Tue, 05 Nov 1996 00:33:19 GMT Server: NCSA/1.5 Content-type: text/html Last-modified: Wed, 28 Aug 1996 05:46:10 GMT Content-length: 19759
A floating point underflow can be caused by uninitialized variables. If you declare some floats or doubles and don't set them to some value before you use them, they may start out with huge or tiny values that cause errors in calculations. The simple fix is to initialize all your floats to zero.
A division by zero error may not be obvious to look at the code, but can
occur when variables have unexpected values. Often you will be performing
some calculation inside a loop, and the loop goes one place too far or the
very first or very last iterations form special cases, resulting in a
division by zero. Unless you can spot it right away, the best way to find
such an error is probably to use the debugger to track down the offending
line of code. Then you can run the program again and
use the watch feature to view the variables involved, and see what causes
things to run afoul.
This is a very common problem. There can be problems when you mix "cin >>"
and "cin.getline" input statements in a program. The "cin >>" function will
take input, but it leaves a newline character in the input buffer. If a
getline call follow a "cin >>", then the getline will read this single newline
character and stop. It will appear as if the getline read nothing at all.
So whenever you have a getline following a "cin >>" you must clear the
newline character from the buffer either with a "cin.ignore" or another
"cin.getline". This should, of course, be placed between the "cin >>" and
the "cin.getline" that really takes input. Here's an example that suffers
from this error:
cin >> GolfScore; cin.getline( PlayerName, MAX_STR, '\n' );In this case the PlayerName would just get the null string because of the newline character left in the input buffer by the "cin >>". Here are the two ways to problem can be fixed.
cin >> GolfScore; cin.ignore( MAX_STR, '\n' ); cin.getline( PlayerName, MAX_STR, '\n' );or
cin >> GolfScore; cin.getline( dummy_buffer, MAX_STR, '\n' ); cin.getline( PlayerName, MAX_STR, '\n' );
ifstream input("r:\\public\\jjason\\myfile.in");Also, make sure that if you copied the input file from an instructor, that you copied to the correct directory.
class foo { ... public: void Output(); ... };When you want to print out such an object, students sometimes make the mistake of making the call to the Output member part of a cout:
foo FooA; cout << "The object is " << FooA.Output() << ". Cool, eh?" << endl;The Output function works on its own, and should not be a part of a cout. Despite the odd notation, "cout <<" is a function call, and the function is only able to print out numbers, strings, and characters. The correct way to achieve the intention above is:
cout << "The object is "; FooA.Output(); cout << ". Cool, eh?" << endl;