Demonstrate DO ... while loop - C++ Statement

C++ examples for Statement:do while

Description

Demonstrate DO ... while loop

Demo Code

#include <iostream>
using namespace std;
int main()/*ww w.  j  a v  a  2s . c om*/
{
   long dividend, divisor;
   char ch;
   do                                   //start of do loop
   {                                 //do some processing
       cout << "Enter dividend: "; cin >> dividend;
       cout << "Enter divisor: ";  cin >> divisor;
       cout << "Quotient is " << dividend / divisor;
       cout << ", remainder is " << dividend % divisor;
       cout << "\nDo another? (y/n): ";  //do it again?
       cin >> ch;
   }
   while( ch != 'n' );                  //loop condition
   return 0;
}

Result


Related Tutorials