Introduction: C++: Countdown With "for" Loop

About: Occupation: tech support

C++ program that counts down from a number that the user enters.

#include <iostream>
#include <string>

using namespace std;

int main()

{ // start main function

int alpha;
int countdown;

cout << "Enter number to countdown from: ";
cin >> countdown;

for (alpha=0; alpha<=countdown; countdown--)
{
cout << "Countdown at: " << countdown << endl;
if (countdown==0)
cout << "Liftoff!";
} // end for loop


return 0;

} // end main function

Supplies

  1. Desktop or laptop computer.
  2. Code::Blocks IDE for C++ programming.

Step 1: C++ Program That Counts Down From a Number That a User Enters

C++ program that counts down from a number that the user enters.

using namespace std;

int main()

{ // start main function

int alpha;
int countdown;

cout << "Enter number to countdown from: ";
cin >> countdown;

for (alpha=0; alpha<=countdown; countdown--)
{
cout << "Countdown at: " << countdown << endl;
if (countdown==0)
cout << "Liftoff!";
} // end for loop


return 0;

} // end main function