An Example of a do-while Loop
#include <iostream.h>
/**********************************************************************
Program: do_loop.C
This program computes an average of all the numbers keyed in
This program has errors
**********************************************************************/
int main()
{
int num = 0, count = 0, total = 0;
do {
cout << "Enter a whole number, and -99 to quit:";
cin >> num; // accept input
count++; // increment counter
total += num; //accumulate the sum
} while (num != -99); // test the condition
cout << "You keyed in " << count << " numbers \n";
cout << "The average is " << float(total)/count << endl;
return(0);
}
Back to Previous Page
Document:
Local Date:
Last Modified On: