home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C Programming Starter Kit 2.0
/
SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso
/
tybc4
/
for3.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1993-03-22
|
688b
|
32 lines
// 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;
}