divdo.cpp


// divdo.cpp
// demonstrates DO loop
#include <iostream>
using namespace std;

int main()
{
	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;
}


Results

C:\classes\ece538\work>divdo
Enter dividend: 20
Enter divisor: 4
Quotient is 5, remainder is 0
Do another? (y/n): y
Enter dividend: 126
Enter divisor: 12
Quotient is 10, remainder is 6
Do another? (y/n): n


Maintained by John Loomis, updated Mon Jan 01 12:42:12 2007