C++/Language/Do While
Версия от 14:21, 25 мая 2010; (обсуждение)
Do while loop with a input manipulator
#include <iostream>
#include <cstring>
using namespace std;
istream &getpass(istream &stream)
{
cout << "\a"; // sound bell
cout << "Enter password: ";
return stream;
}
int main()
{
char pw[80];
do {
cin >> getpass >> pw;
} while (strcmp(pw, "password"));
cout << "Logon complete\n";
return 0;
}
Do while loop with double value type
#include <iostream>
using namespace std;
int main()
{
double feet;
do {
cout << "Enter feet (0 to quit): ";
cin >> feet;
cout << feet * 12 << " inches\n";
} while (feet != 0.0);
return 0;
}
Do while statement
#include <iostream>
using namespace std;
const long delay = 10000000L;
int main()
{
int tic;
cout << "How often should be output? ";
cin >> tic;
do
{
for( long i = 0; i < delay; ++i )
;
cout << "Output!\a" << endl;
}
while( --tic > 0 );
return 0;
}