SOURCE FILE: 7.02CountDownFor-Loop.cpp
// Test program for CountDown of Example 7.2
#include <iostream.h>
#include <iomanip.h>
int main(void)
{
void CountDown(int);
CountDown(10);
return 0;
}
//
// Example 7.2. Function to count down from positive parameter
// CountFrom to 1 and then to print Ignition, Blast off!
// Pre: CountFrom is a positive integer.
// Post: The countdown was displayed.
//
void CountDown(int CountFrom)
{
if (CountFrom <= 0) // invalid parameter
cout << "ERROR: Counting down from " << CountFrom << " <= 0\n";
else // valid parameter
{
for (; CountFrom > 0; CountFrom--)
cout << setw(5) << CountFrom << endl;
cout << "Ignition\n";
cout << "Blast off!\n";
}
}