home *** CD-ROM | disk | FTP | other *** search
- // Program that demonstrates using the
- // for loop to emulate an infinite loop.
-
- #include <iostream.h>
- #include <ctype.h>
-
- main()
- {
- char ch;
- double x, y;
-
- // for loop with empty parts
- for (;;) {
- cout << "\nEnter a number : ";
- cin >> x;
- // process number if non-zero
- if (x != 0) {
- y = 1/ x;
- cout << "1/(" << x << ") = " << y << "\n";
- cout << "More calculations? (Y/N) ";
- cin >> ch;
- ch = toupper(ch);
- if (ch != 'Y')
- break;
- }
- else
- // display error message
- cout << "Error: cannot accept 0\n";
- }
- return 0;
- }
-